Programmer Guide/Shell Items/File/SET FILE: Difference between revisions
(→STATUS) |
|||
(158 intermediate revisions by 5 users not shown) | |||
Line 1: | Line 1: | ||
{{DISPLAYTITLE:{{SUBPAGENAME}}}} | {{DISPLAYTITLE:{{SUBPAGENAME}}}} | ||
{{File Item}} | |||
==Binary File Commands== | ==Binary File Commands== | ||
===LIST=== | === Binary Files: <code>LIST</code> === <!-- C.G.: Headings must be unique within a Wiki document! --> | ||
SET <var>bfile</var> LIST <var>table</var> | SET <var>bfile</var> LIST <var>table</var> | ||
Line 14: | Line 15: | ||
1|…|4 rows columns I16|I32|F32|F64 | 1|…|4 rows columns I16|I32|F32|F64 | ||
===LOAD=== | ===Binary Files: <code>LOAD</code> === <!-- C.G. headings must be unique! --> | ||
SET <var>bfile</var> LOAD <var>numitem</var> <var>section</var> | SET <var>bfile</var> LOAD <var>numitem</var> <var>section</var> | ||
{| | {| | ||
Line 26: | Line 27: | ||
Load a section from a binary file into a numeric shell item. | Load a section from a binary file into a numeric shell item. | ||
===SAVE=== | === Binary Files: <code>SAVE</code> === <!-- C.G. headings must be unique! --> | ||
SET <var>bfile</var> SAVE <var>numitem</var> [ <var>section</var> ] [ /1|2|3|4] | SET <var>bfile</var> SAVE <var>numitem</var> [ <var>section</var> ] [ /1|2|3|4] | ||
{| | {| | ||
Line 34: | Line 35: | ||
|- | |- | ||
| <var>section</var> | | <var>section</var> | ||
| The section index (<code>0</code>,<code>1</code>,…) | | The section index (<code>0</code>,<code>1</code>,…) of an existing section. Leave empty to append a section. | ||
|- | |- | ||
| <code>/n</code> | | <code>/n</code> | ||
Line 45: | Line 46: | ||
==Finding Files on Disk== | ==Finding Files on Disk== | ||
===FIND=== | === Finding Files: <code>FIND</code> === <!-- C.G.: Headings must be unique within a Wiki page! --> | ||
SET <var>file</var> FIND <var>search</var> [ / | SET <var>file</var> FIND <var>search</var> [ /File | /Directory ] | ||
The command <code>FIND</code> starts a new search for files or directories located in the current directory and matching the <var>search</var> string (a file or directory name containing normal Windows wildcards). | The command <code>FIND</code> starts a new search for files or directories located in the current directory and matching the <var>search</var> string (a file or directory name containing normal Windows wildcards). | ||
The command <code>NEXT</code> looks for the next file matching the <var>search</var> specified in the <code>FIND</code> command. Both commands return an error if no (more) matching files were found. If the return code (< | The command <code>NEXT</code> looks for the next file matching the <var>search</var> specified in the <code>FIND</code> command. Both commands return an error if no (more) matching files were found. If the return code (<var>RC</var>) is zero, a matching file was found and its name etc. can be accessed via the [[Programmer Guide/Shell Items/File/FILE Item Attributes|file item attributes]]. The file item <var>file</var> must be a [[Programmer_Guide/Shell_Items/File/NEW_FILE#List_File_Items|list file item]] (see [[Programmer_Guide/Shell_Items/File/NEW_FILE#List_File_Items|<code>NEW FILE</code>]]). | ||
{| | {| | ||
Line 59: | Line 60: | ||
|- | |- | ||
| <code>/File</code> or <code>/Directory</code> | | <code>/File</code> or <code>/Directory</code> | ||
| If the option <code>/F</code> is specified, files are searched for, if <code>/D</code> is specified, directories are searched for. The default is /F. | | If the option <code>/F</code> is specified, files are searched for, if <code>/D</code> is specified, directories are searched for. The default is <code>/F</code>. | ||
|} | |} | ||
===NEXT=== | ===Finding Files: <code>NEXT</code>=== <!-- C.G.: Headings must be unique within a Wiki page! --> | ||
SET <var>file</var> NEXT | SET <var>file</var> NEXT | ||
Line 72: | Line 73: | ||
These commands can be applied to a [[Programmer_Guide/Shell_Items/File/NEW_FILE#File_System_Items|file system file item]] (also called dummy file item). | These commands can be applied to a [[Programmer_Guide/Shell_Items/File/NEW_FILE#File_System_Items|file system file item]] (also called dummy file item). | ||
===STATUS=== | === Status Files: <code id="STATUS">STATUS</code> === <!-- C.G. headings must be unique! --> | ||
SET <var>file</var> STATUS <var>path</var> [ [[Programmer_Guide/Command_Reference_Options/Silent|/Silent]] ] | SET <var>file</var> STATUS <var>path</var> [ [[Programmer_Guide/Command_Reference_Options/Silent|/Silent]] ] | ||
Retrieve the status of file <var>path</var>. If the file <var>path</var> exists (on disk), all available status values are retrieved and can be accessed via the file-item attributes. The file item <var>file</var> must be of type file. | Retrieve the status of file <var>path</var>. If the file <var>path</var> exists (on disk), all available status values are retrieved and can be accessed via the file-item attributes. The file item <var>file</var> must be of type ''file''. | ||
{| | {| | ||
Line 82: | Line 83: | ||
| <code>/Silent</code> | | <code>/Silent</code> | ||
| If specified, errors will generate warning messages rather than error messages. See [[Programmer_Guide/Command_Reference_Options/Silent|The Silent Flag]] for details. | | If specified, errors will generate warning messages rather than error messages. See [[Programmer_Guide/Command_Reference_Options/Silent|The Silent Flag]] for details. | ||
} | |} | ||
===DELETE=== | === Status Files: <code id="DELETE">DELETE</code> === <!-- C.G. headings must be unique! --> | ||
SET <var>file</var> DELETE <var>path</var> [ [[Programmer_Guide/Command_Reference_Options/Silent|/Silent]] ] | |||
Delete the file <var>path</var>. The command will fail if <var>file</var> is not | Delete the file <var>path</var>. The command will fail if <var>file</var> is not an actual file (but a directory, a file system file item, or the like). | ||
{| | |||
|- | |||
| <code>/Silent</code> | |||
| If specified, errors will generate warning messages rather than error messages. See [[Programmer_Guide/Command_Reference_Options/Silent|The Silent Flag]] for details. | |||
|} | |||
: | === Status Files: <code id="RENAME">RENAME</code> and <code id="COPY">COPY</code> === <!-- C.G. headings must be unique! --> | ||
SET <var>file</var> RENAME|COPY <var>path</var> <var>newpath</var> [ [[Programmer_Guide/Command_Reference_Options/Silent|/Silent]] ] | |||
< | Rename or copy the file <var>path</var>. The file item <var>file</var> must be a file system file item (as opposed to a directory, a file system file item, and the like). The <code>RENAME</code> function can also be used to move a file into another directory or to another disk drive or network-directory (located on another computer). Note that the <code>RENAME</code> command will fail if the <var>newpath</var> already exists, whilst the <code>COPY</code> command will silently overwrite an existing target file. | ||
{| | |||
|- | |||
| <code>/Silent</code> | |||
| If specified, errors will generate warning messages rather than error messages. See [[Programmer_Guide/Command_Reference_Options/Silent|The Silent Flag]] for details. | |||
|} | |||
==Text and Section File I/O== | ==Text and Section File I/O== | ||
The <code> | The <code>SET FILE</code> commands <code>LIST</code>, <code>[[#Text_Files:_LOAD|LOAD]]</code> and <code>SAVE</code> access the content of files attached to file items of type <code>TEXT</code> or <code>SECTION</code> (see [[Programmer_Guide/Shell_Items/File/NEW_FILE#Text_Files|<code>NEW FILE … /Text</code>]] and [[Programmer_Guide/Shell_Items/File/NEW_FILE#Section_Files|<code>NEW FILE … /Section</code>]]). Note that you can also use the command [[Programmer_Guide/Command_Reference/WRITE|<code>WRITE</code>]] to write data to a file item. | ||
SET <var>file</var> <var>cmd</var> <var>table</var> [<var>type</var> <var>name</var>] | |||
{| | |||
|- | |||
| <var>cmd</var> | |||
| Either <code>LIST</code>, <code>LOAD</code> or <code>SAVE</code> (see below). | |||
|- | |||
| <var>table</var> | |||
| A table to load data into or read data from. | |||
|- | |||
| <var>type</var> | |||
| Either <code>TEXT</code> or <code>SECTION.</code> | |||
|- | |||
| <var>name</var> | |||
| A section name. | |||
|} | |||
A section is defined by its <var>type</var> and a <var>name</var>, the latter being optional if there is only one section of the same <var>type</var>. Both are strings which may not contain the characters "<code>$</code>", "<code>[</code>" , "<code>]</code>", "<code>;</code>" or "<code>'</code>" (single quotes). The <var>name</var> may consist of more than one word. | |||
Note that the mode in which the file is read or written is dependent on the flags passed to the <code>NEW FILE</code> command. | |||
: | === Text Files: <code>LIST</code> === <!-- C.G. headings must be unique! --> | ||
SET <var>file</var> LIST <var>table</var> [ <var>type</var>|* <var>name</var>|* ] | |||
Retrieve a list of sections from a [[Programmer_Guide/Shell_Items/File/NEW_FILE#Section_Files|section file]] (not applicable for other file item types). One table entry with the following format is created per section: | |||
sectionType sectionName | |||
{| | |||
| <var>table</var> | |||
| The simple table to append the section list to. | |||
|- | |||
| <var>type</var> | |||
| The type of sections to list. If no type or an asterisk is specified , all sections are listed. | |||
|- | |||
| <var>name</var> | |||
| The name of the sections to list. If no name or an asterisk is specified, all sections of type <var>type</var> are listed. | |||
|} | |||
=== Text Files: <code>LOAD</code> === <!-- C.G. headings must be unique! --> | |||
The file item <code>LOAD</code> command loads the contents of a file into a table. Both LOAD variants support the [[Programmer_Guide/Command_Reference_Options/Silent|/Silent]] option. | |||
SET <var>file</var> LOAD <var>table</var> [ /Silent ] '''// text file''' | |||
SET <var>file</var> LOAD <var>table</var> <var>type</var> <var>name</var> [ /Silent ] '''// section file''' | |||
Load the whole content of the file (in case of a [[Programmer_Guide/Shell_Items/File/NEW_FILE#Text_Files|text file]]) or of a section (in case of a [[Programmer_Guide/Shell_Items/File/NEW_FILE#Section_Files|section file]]), and append the loaded data to the table item <var>table</var>. If the table is an extended or a parameter table, please use the table [[Programmer_Guide/Shell_Items/Table/SET_TABLE#FORMAT|<code>FORMAT</code> command]] to appropriately configure the input formatting options first. | |||
{| | |||
| <var>table</var> | |||
| A simple, extended or parameter table which will have data appended to it. | |||
|- | |||
| <var>type</var> | |||
| The section type to load. There is no default. | |||
|- | |||
| <var>name</var> | |||
| The name of the section to load. There is no default. | |||
|- | |||
| <code>/Silent</code> | |||
| If specified, errors will generate warning messages rather than error messages. See [[Programmer_Guide/Command_Reference_Options/Silent|The Silent Flag]] for details. | |||
|} | |||
Note that you can load a CSV file by setting the delimiter of the table you are loading into. See [[Programmer_Guide/Shell_Items/Table/SET_TABLE#Formatting_table_fields|Formatting_table_fields]]. | |||
See <code>load_a_file_into_a_table.sts</code> in the script examples directory for a working example. | See <code>load_a_file_into_a_table.sts</code> in the script examples directory for a working example. | ||
===SAVE=== | === Text Files: <code>SAVE</code> === <!-- C.G. headings must be unique! --> | ||
Save the contents of a shell table item into a file. | Save the contents of a shell table item into a file. | ||
SET <var>textFile</var> SAVE <var>table</var> [ [[Programmer_Guide/Command_Reference_Options/Silent|/Silent]] ] | |||
Saves the content of the table item <var>table</var> to a <code>TEXT</code> file. | Saves the content of the table item <var>table</var> to a <code>TEXT</code> file. | ||
{| | |||
| <var>table</var> | |||
| The table containing the text to save to file. | |||
|- | |||
| <code>/Silent</code> | |||
| If specified, errors will generate warning messages rather than error messages. See [[Programmer_Guide/Command_Reference_Options/Silent|The Silent Flag]] for details. | |||
|} | |||
SET <var>sectionFile</var> SAVE <var>table</var> <var>type</var> [<var>name</var>] [ [[Programmer_Guide/Command_Reference_Options/Silent|/Silent]] ] | |||
Saves the content of the table item <var>table</var> to a section <var>name</var> of type <var>type</var> in a [[Programmer_Guide/Shell_Items/File/NEW_FILE#Section_Files|section file]]. Saving an empty table to a section will delete the section. | |||
{| | |||
| <var>table</var> | |||
| The table containing the text to save to file. | |||
|- | |||
| <var>type</var> | |||
| The type of the section (e.g. the section <code>[macro myTestMacro]</code> has the type <code>macro</code>). This parameter is mandatory. | |||
|- | |||
| <var>name</var> | |||
| The name of the section (e.g. the section <code>[macro myTestMacro]</code> has the name <code>myTestMacro</code>). | |||
|- | |||
| <code>/Silent</code> | |||
| If specified, errors will generate warning messages rather than error messages. See [[Programmer_Guide/Command_Reference_Options/Silent|The Silent Flag]] for details. | |||
|} | |||
<code> | === Text Files: <code>SYNC</code> === <!-- C.G. headings must be unique! --> | ||
SET <var>file</var> SYNC | |||
Write section file from memory to disk. | |||
==Locking / Unlocking File Items== | ==Locking / Unlocking File Items== | ||
The use of '''lock/unlock''' is only important, if a file item is (or may be) used by more than one thread. In {{STX}} shells, spu items and display item are running in their own thread. | |||
< | SET <var>file</var> LOCK | ||
Lock the file item <var>file</var>. The execution of the calling shell is stopped, until the file item can be locked. If locked, only the shell which locked it has access to its content. The file must be explicitly unlocked with the command <code>UNLOCK</code>. Always beware deadlocks. | |||
SET <var>file</var> LOCK <var>timeout</var> | |||
Try to lock the file item <var>file</var>, but wait only the specified time. This command returns '''0''' (success) if the lock request was successful within the timeout, and a non-zero error code if not. If the caller already ''holds'' the lock, the command will fail immediately. This makes sense because, since the caller is the owner, it cannot release it whilst its waiting. The argument <var>timeout</var> specifies the maximum lock-timeout in milliseconds and must be a number greater than zero. | |||
SET <var>file</var> UNLOCK | |||
Unlock the file item <var>file</var>. '''Note''': Its very important that for each successful <code>LOCK</code> an <code>UNLOCK</code> is called! | |||
: | |||
<code> | |||
<code> | |||
==XML Doctype== | ==XML Doctype== | ||
The {{STX}} XML implementation supports an element type definition which is not directly compatible with the standard XML definition methods like DTD or XML Schema. If necessary we will | The {{STX}} XML implementation supports an element type definition which is not directly compatible with the standard XML definition methods like DTD or XML Schema. If necessary we will add an interface to a standard in the future. The XML element definitions are created with the command <code>SET xmlfile DOCTYPE …</code> as documented below. All definition commands should be applied before the XML content is accessed. The sequence of definition commands must be finished with the command <code>SET xmlfile DOCTYPE CLOSE</code> to verify and initialize the element types. The element type definitions are not mandatory. They are applied during XML access only if available. | ||
The following notes apply to the commands below: | The following notes apply to the commands below: | ||
* If an element is derived from a parent element, it inherits all children, all attributes and the base and not-base element. All inherited definitions can be overridden in the derived element. | |||
* If a base element is defined, elements of type tag can only be added to a position below (inside) the base element or an element derived from the base element. | |||
* If a none-base element is defined, elements of type tag can not be added to a position below (inside) the none-base element or an element derived from the none-base element. | |||
* If an undefined element tag is used as argument (e.g. parent, base or in the child command) an element type tag is created automatically (and should be selected and configured later). | |||
* If children are set to invisible, all element below/inside the element are hidden | |||
* The default attribute visibility is used for undefined attributes and for attributes without visibility setting. | |||
* A valid definition sequence (i.e., the sequence of all <code>DOCTYPE</code> commands before <code>DOCTYPE CLOSE</code>) must consist of at least one element definition and the root and name assignment. | |||
{{STX}} has a predefined <code>DOCTYPE</code> (defined in the <code>stxconfig.xml</code> file), which guarantees data integrity. | |||
* | // A very basic doctype example | ||
$#xml doctype name 'testdoctype' | |||
$#xml doctype element root * * * * yes yes yes | |||
$#xml doctype root root | |||
$#xml doctype element elem * * * * yes yes yes | |||
$#xml doctype attribute type yes all default string no yes | |||
$#xml doctype close | |||
===<code>DOCTYPE ELEMENT</code>=== | |||
SET <var>xmlfile</var> DOCTYPE ELEMENT <var>tag</var> [<var>parent</var> <var>base</var> <var>nobase</var> <var>data</var> <var>vtag</var> <var>vchildren</var> <var>vattributes</var>] | |||
Create a new element type or select an element type (e.g. to define children or attributes). See [[Note 7]]. <!-- WTF is Note 7? --> | |||
Create a new element type or select an element type (e.g. to define children or attributes). See Note 7. | |||
{| | {| | ||
|- | |- | ||
|tag | |<var>tag</var> | ||
|tag name of the element type | |tag name of the element type | ||
|- | |- | ||
|parent | |<var>parent</var> | ||
|tag name of the parent type or * if none (1)(4) | |tag name of the parent type or <code>*</code> if none [[Note 1|(1)]] [[Note 4|(4)]] <!-- WTF? --> | ||
|- | |- | ||
|base | |<var>base</var> | ||
|tag name of the base element or <code>*</code> (2)(4) | |tag name of the base element or <code>*</code> [[Note 2|(2)]] [[Note 4|(4)]] <!-- WTF? --> | ||
|- | |- | ||
|nobase | |<var>nobase</var> | ||
|tag name of the not<nowiki>-</nowiki>base element or <code>*</code> (3)(4) | |tag name of the not<nowiki>-</nowiki>base element or <code>*</code> [[Note 3|(3)]] [[Note 4|(4)]] <!-- WTF? --> | ||
|- | |- | ||
|data | |<var>data</var> | ||
|a string defining the type of the data section (currently unused) | |a string defining the type of the data section (currently unused) | ||
|- | |- | ||
|vtag | |<var>vtag</var> | ||
|show tag in dialogs | |show tag in dialogs (<code>no</code>> or <code>yes</code>) | ||
|- | |- | ||
|vchildren | |<var>vchildren</var> | ||
|show children in dialogs | |show children in dialogs (<code>no</code>> or <code>yes</code>) [[Note 5|(5)]] <!-- WTF? --> | ||
|- | |- | ||
|vattributes | |<var>vattributes</var> | ||
|default visibility of attributes in dialogs | |default visibility of attributes in dialogs (<code>no</code>>, <code>yes</code> or <code>all</code>) [[Note 6|(6)]] <!-- WTF? --> | ||
|} | |} | ||
===<code>DOCTYPE CHILD</code>=== | |||
SET <var>xmlfile</var> DOCTYPE CHILD <var>tag</var> <var>minoccur</var> <var>maxoccur</var> | |||
Add a child element definition to the last created/selected element. | Add a child element definition to the last created/selected element. | ||
Line 348: | Line 298: | ||
{| | {| | ||
|- | |- | ||
|tag | |<var>tag</var> | ||
|tag name of the child element (4) | |tag name of the child element [[Note 4|(4)]] <!-- WTF? --> | ||
|- | |- | ||
|minoccur | |<var>minoccur</var> | ||
|minimum number of occurrences ( | |minimum number of occurrences (must be ≥ 0 or <code>*</code> meaning 0 occurences) | ||
|- | |- | ||
|maxoccur | |<var>maxoccur</var> | ||
|maximum number of occurrences ( | |maximum number of occurrences (must be ≥ minoccur or <code>*</code> meaning ℵ<sub>0</sub>) | ||
|} | |} | ||
===<code>DOCTYPE ROOT</code>=== | |||
SET <var>xmlfile</var> DOCTYPE ROOT <var>tag</var> | |||
Assign the type tag of the root element. The element type must have been defined [[Note 7|(7)]]. <!-- WTF? --> | |||
<code | ===<code>DOCTYPE NAME</code>=== | ||
SET <var>xmlfile</var> DOCTYPE NAME <var>anytext</var> [[Note 7|(7)]] <!-- WTF? --> | |||
Assign the title/name of the element definition [[Note 7|(7)]]. <!-- WTF? --> | |||
<code | ===<code>DOCTYPE CLOSE</code>=== | ||
SET <var>xmlfile</var> DOCTYPE CLOSE | |||
Close definition sequence. Initialise and verify all types. This must be the last command of the definition sequence [[Note 7|(7)]]. <!-- WTF? --> | |||
<code> | ===<code>VALIDATE</code>=== | ||
SET <var>xmlfile</var> VALIDATE <var>errorTable</var>|<var>*</var> [<var>testdoc</var> /Insert] [/Recursive] [/Position /Children /Attributes] [/Showposition] | |||
Validate the <var>xmlfile</var>'s selected element using the defined doctype. If all tests are passed, or if no doctype is defined, it sets <var>RC</var> to <samp>0</samp>. A simple table (<var>errorTable</var>) can be passed, to log errors in. The tests can be performed on either just the selected element or the selected element and all elements within it (<code>/Recursive</code>). The position (<code>/Position</code>), attributes (<code>/Attributes</code>) and the occurrence of children (<code>/Children</code>) can be tested. If a test document (<var>testdoc</var>) is passed, the test document's selected element is validated (instead of the <var>xmlfile</var>) using the <var>xmlfile</var>'s doctype. If the option <code>/Insert</code> is used in conjunction with <var>testdoc</var>, the test document's selected element is validated as if it were inserted at the position of the <var>xmlfile</var>'s selected element. If no options are given, the options <code>/R/P/C/A</code> are used by default. The option <code>/Showposition</code> modifies any error strings, prefixing the string with a position id (leading to e.g. "e;<code>P#54 ASeg has invalid attributes</code>"e;). | |||
{| | |||
| <var>errorTable</var> | |||
| A simple table in which to log errors. | |||
|- | |||
| <var>testdoc</var> | |||
| An XML shell-file to be tested against the defined DOCTYPE. | |||
|} | |||
==XML Element and Attribute Manipulation== | ==XML Element and Attribute Manipulation== | ||
All commands act on the 'selected' element unless otherwise indicated. On loading an XML file, the selected element is set to the root element. Navigating through the file then selects different elements. | All commands act on the ''selected'' element unless otherwise indicated. On loading an XML file, the selected element is set to the root element. Navigating through the file then selects different elements. | ||
===ADDELEMENT=== | ===XML: <code id="ADDELEMENT">ADDELEMENT</code>=== | ||
SET <var>xmlfile</var> ADDELEMENT <var>ename</var>|<var>xmlSourceFile</var> [<var>aname</var> <var>avalue</var> …] [/Before|After|Replace /In|Out /First|Last /Copy] | |||
Create a new empty element with tag <var>ename</var>. | Create a new empty element with tag <var>ename</var>. | ||
The element is inserted before (/Before) or after (/After | The element is inserted ''before'' (<code>/Before</code>) or ''after'' (<code>/After</code>, which is the default) the selected element of <var>xmlfile</var> or it ''replaces'' (<code>/Replace</code>) the selected element. Attribute assignments (<code><var>aname</var> <var>avalue</var></code>) can be specified to set element attributes on the fly. | ||
If a doctype has been defined, the element's position and attributes are validated and the function fails if the parameters are invalid. Required attributes which were not passed | If a doctype has been defined, the element's position and attributes are validated and the function fails if the parameters are invalid. Required attributes which were not passed are set to their default values. | ||
When the option / | When the option <code>/Copy</code> is used in conjunction with an <var>xmlSourceFile</var> (instead of an <var>ename</var>), the selected element of <var>xmlSourceFile</var> is added. | ||
The navigation options are applied as follows: The option /Out is carried out before adding the element. The options /First | The navigation options are applied as follows: The option <code>/Out</code> is carried out ''before'' adding the element. The options <code>/First</code> or <code>/Last</code> are then performed. After the element is added, the <code>/In</code> option is carried out. | ||
===ADDFILE=== | ===XML: <code id="ADDFILE">ADDFILE</code>=== | ||
SET <var>xmlfile</var> ADDFILE <var>source</var> [/After|Before|Replace] [/In|Out] [/Delete] [/Children] [/Novalidate] | |||
Copy the selected element from XML file-item <var>source</var> to <var>xmlfile</var>. The element is inserted before (/Before) or after (/After | Copy the selected element from XML file-item <var>source</var> to <var>xmlfile</var>. The element is inserted ''before'' (<code>/Before</code>) or ''after'' (<code>/After</code> which is the default) the selected element of <var>xmlfile</var>, or it ''replaces'' the selected element (<code>/Replace</code>). If the option <code>/Delete</code> is specified, the copied element is removed from <var>source</var> and the next (source) element (if any) is selected. If no navigation option is specified, the added element is selected. Possible navigation options are <code>/In</code> (step into the added element, ''after'' add) and <code>/Out</code> (step out of current parent, ''before'' add). | ||
{| | |||
| <var>source</var> | |||
| The source XML file item to be added. | |||
|- | |||
| <code>/After</code>, <code>/Before</code> or <code>/Replace</code> | |||
| Insert the <var>source</var> file after or before the selected element, or replace the selected element. | |||
|- | |||
| <code>/In</code> or <code>Out</code> | |||
| Navigate out of the selected <var>xmlfile</var> element before add or navigate into the <var>xmlfile</var> selected element after add. | |||
|- | |||
| <code>/Delete</code> | |||
| Delete the sources selected element from the source file once it has been added. | |||
|- | |||
| <code>/Children</code> | |||
| If this flag is specified, all children of the current <var>source</var> element are added to the current element of the target file (as children). In this case all other options except <code>/Novalidate</code> are ignored! | |||
|- | |||
| <code>/Novalidate</code> | |||
| Disable validation (do not validate source data) | |||
|} | |||
* Note that if adding the file at root level, the root element will be replaced no matter what <code>/A</code>, <code>/B</code> and <code>/R</code> options are given. | |||
* Note that if the root element of the source document is added, the nodes on that level (e.g. the <code><?xml?></code> and <code><!DOCTYPE></code> entries) are not copied. | |||
This function sets <var>RC</var> to <samp>0</samp> on success. | |||
: | ===XML: <code id="DOCTYPE_ATTRIBUTE">DOCTYPE ATTRIBUTE</code>=== | ||
SET <var>xmlfile</var> DOCTYPE ATTRIBUTE <var>name</var> <var>required</var> <var>visibility</var> <var>default</var> <var>type</var> <var>params</var> | |||
Add an attribute definition to the last created/selected element. | Add an attribute definition to the last created/selected element. | ||
Line 450: | Line 397: | ||
{| | {| | ||
|- | |- | ||
|name | |<var>name</var> | ||
|attribute name | |attribute name | ||
|- | |- | ||
|required | |<var>required</var> | ||
|attribute is required (<code>yes</code> | |attribute is required (<code>yes</code> or <code>no</code>) | ||
|- | |- | ||
|visibility | |<var>visibility</var> | ||
|visibility of attribute in dialogs (<code>no</code> | |visibility of attribute in dialogs (<code>no</code>…hidden, <code>yes</code>…show value, <code>all</code>…show name and value) | ||
|- | |- | ||
|default | |<var>default</var> | ||
|default value or <code>*</code> for no default | |default value or <code>*</code> for no default | ||
|- | |- | ||
|type, params | |<var>type</var>, <var>params</var> | ||
|attribute data type and configuration parameters:{| | |attribute data type and configuration parameters: | ||
{| | |||
|- | |- | ||
|type | |type | ||
Line 469: | Line 417: | ||
|- | |- | ||
|<code>INTEGER</code> | |<code>INTEGER</code> | ||
|minimum maximum | |<var>minimum</var> <var>maximum</var> | ||
|- | |- | ||
|<code>NUMBER</code> | |<code>NUMBER</code> | ||
|minimum maximum | |<var>minimum</var> <var>maximum</var> | ||
|- | |- | ||
|<code>STRING</code> | |<code>STRING</code> | ||
|respectcase unique | |<var>respectcase</var> <var>unique</var> | ||
|- | |- | ||
|<code>VALUELIST</code> | |<code>VALUELIST</code> | ||
| | |<code><var>value<sub>1</sub></var> <var>value<sub>2</sub></var>…</code> | ||
|} | |} | ||
|- | |- | ||
|minimum | |<var>minimum</var> | ||
|minimum value or <code>*</code> for infinite | |minimum value or <code>*</code> for infinite | ||
|- | |- | ||
|maximum | |<var>maximum</var> | ||
|maximum value or <code>*</code> for infinite | |maximum value or <code>*</code> for infinite | ||
|- | |- | ||
|respectcase | |<var>respectcase</var> | ||
|respect (<code>yes</code>) or ignore (<code>no</code>) case in search/compare functions | |respect (<code>yes</code>) or ignore (<code>no</code>) case in search/compare functions | ||
|- | |- | ||
|unique | |<var>unique</var> | ||
|value must be unique (<code>yes</code>) on the elements level or not (<code>no</code>) | |value must be unique (<code>yes</code>) on the elements level or not (<code>no</code>) | ||
|- | |- | ||
| | |<var>value<sub>1</sub></var>, <var>value<sub>2</sub></var> | ||
|possible values | |possible values for a valuelist attribute | ||
|} | |} | ||
===XML: <code id="ADDNODE">ADDNODE</code>=== | |||
SET xmlfile ADDNODE <var>text</var> [<var>aname</var> <var>avalue</var> …] /Comment|DocType|Element|ProcInst [/Before|After|Replace /In|Out /First|Last] | |||
= | Add a node to the XML-file. The node types supported are ''processing instructions'' (<code><?xml version="1.0"?></code>), ''elements'' (<item>data</item>), ''document types'' (<code><!DOCTYPE section SYSTEM "stx.dtd"></code>) and ''comments'' (<code><!—comment --></code>). The <var>text</var> has a different meaning for each node type: for a processing instruction it is the target ''xml'', for an element it is the tag ''item'', for the document type it is the text between "<code><!DOCTYPE </code>" and "<code>></code>" and for a comment it is the text within the comment markers. Element nodes may be assigned attributes (<code><var>aname</var> <var>avalue</var></code>). The options <code>/First</code> and <code>/Last</code> navigate to the first or last node on this level (independent of the node type being added). If a doctype has been defined and the node is an element, the element's position and attributes are validated and the function fails if the parameters are invalid. | ||
<code> | ===XML: <code id="ADDTABLE">ADDTABLE</code>=== | ||
SET <var>xmlfile</var> ADDTABLE <var>table</var> <var>ename</var> [/After|Before|Replace] [/In|Out /Data|Empty /Cdata] [/TagErrorsOnly] | |||
Add the entries of <var>table</var> as elements to <var>xmlfile</var>. One element per entry is added, after (<code>/After</code>, which is the default) or before (<code>/Before</code>) the current element, or replacing (<code>/Replace</code>) the current element. The argument <var>ename</var> is used as the element tag. If <code>/Data</code> is specified, the entry data is stored in the element's data section using the table's write format, otherwise (<code>/Empty</code> is the default), the entry data is stored as element attributes (use field names as attribute names, does not store empty fields, uses the write format) and the element data section is empty. In conjunction with <code>/Data</code>, the option <code>/Cdata</code> can be used to create CData sections instead of normal data sections. There is a severe performance hit (1.300%) if you use the <code>/Before</code> option since indexes have to be recalculated. | |||
{| | |||
|- | |||
| <var>table</var> | |||
| A shell table with the entries to be added to the XML file. This parameter is mandatory. | |||
|- | |||
| <var>ename</var> | |||
| The string to be used as the created element's tag. This parameter is mandatory. | |||
|- | |||
| <code>/After</code>, <code>/Before</code> or <code>/Replace</code> | |||
| Specify whether the new elements should be added before (<code>/Before</code>) or after (<code>/A</code>) the selected element or if they even should replace the selected element (<code>/Replace</code>). | |||
|- | |||
| <code>/In</code> or <code>Out</code> | |||
| If specified, <code>/In</code> navigates into the selected element before the new element is added. If specified, <code>/Out</code> navigates out of the selected element after the new element has been added. | |||
|- | |||
| <code>/Data</code> or <code>/Empty</code> | |||
| If <code>/Data</code> is specified, then the entry is stored in the data section of the new element. Otherwise, the data is stored as attribute values. | |||
|- | |||
| <code>/Cdata</code> | |||
| Specify <code>/Cdata</code> if the data should be enclosed within a CData section. | |||
|- | |||
| <code>/TagErrorsOnly</code> | |||
| Specify if entries which cause errors should be tagged in the table but correct entries should be added. Otherwise, if one error occurs, no entries are added. | |||
|} | |||
===XML: <code id="DELETEELEMENT">DELETEELEMENT</code>=== | |||
SET <var>xmlfile</var> DELETEELEMENT [<var>ename</var>] [/Child] | |||
Delete the selected element itself (no arguments) or delete all elements with the tag <var>ename</var> on the current level. If <code>/Child</code> is specified, the selected element's children are deleted, but not the selected element itself. | |||
: | '''Warning:''' This operation can take a very long time! | ||
SET <var>xmlfile</var> DELETEELEMENT <var>table</var> <var>field</var> [/Resetpos /Child /All|Tagged] | |||
Delete all elements found at the positions stored in the column <var>field</var> of the table <var>table</var>. | Delete all elements found at the positions stored in the column <var>field</var> of the table <var>table</var>. | ||
{| | |||
| <code>/Child</code> | |||
| If <code>/Child</code> is specified, the selected element's children are deleted, but not the selected element itself. | |||
|- | |||
| <code>/Resetpos</code> | |||
| The positions are deleted, but not the elements. | |||
|- | |||
| <code>/All</code> | |||
| All table entries are used. This is the default. | |||
|- | |||
| <code>/Tagged</code> | |||
| Only tagged entries are used. | |||
|} | |||
===XML: <code id="EXTRACTFILE">EXTRACTFILE</code>=== | |||
SET <var>xmlfile</var> EXTRACTFILE <var>xmlSubDoc</var> <var>posAttrName</var> [<var>tag<sub>N</sub></var> <var>recursive<sub>N</sub></var> … ] | |||
Extract a selection of elements from a source xml file (<var>xmlfile</var>) into a target xml file (<var>xmlSubDoc</var>). The selection is dependent on the parameters <var>tag<sub>N</sub></var> and <var>recursive<sub>N</sub></var> and is independent of the selected element. The position of the extracted element in <var>xmlfile</var> is stored in the attribute <var>posAttrName</var> in the extracted element in <var>xmlSubDoc</var>. The original tree structure is retained. If no <var>tag<sub>N</sub></var>-names are given, then all positions in <var>xmlSubDoc</var> are removed from <var>xmlfile</var> and the contents of <var>xmlSubDoc</var> are deleted. | |||
Note: the root element is always copied from <var>xmlfile</var> to <var>xmlSubDoc</var>. The pre-call contents (if any) are deleted from <var>xmlSubDoc</var>. | |||
===XML: <code id="EXTRACTTABLE">EXTRACTTABLE</code>=== | |||
There are a number of different flavours of the <code>EXTRACTTABLE</code> command. The flavour used depends on the use of the <code>/Mode</code> flag. | |||
SET <var>xmlfile</var> EXTRACTTABLE <var>extTable</var> <var>posFld</var>|* <var>elemTag</var> <var>tagFld</var> <var>attr1Name</var> <var>attr1Fld</var> … [ /P /R /1|All /Y] | |||
Extract a selection of attribute values from elements with a specific tag on the current level into a table. | Extract a selection of attribute values from elements with a specific tag on the current level into a table. | ||
{| | |||
|- | |||
| <var>extTable</var> | |||
| The id of an extended table item. | |||
|- | |||
| <var>posFld</var> | |||
| The name of the table field where element positions should be stored. If the option <code>/P</code> is specified, the position of the element's parent is save instead. | |||
|- | |||
| <var>elemTag</var> | |||
| The name of the element tag (e.g. "AFile" for <AFile> elements) or an asterisk for all elements. | |||
|- | |||
| <var>tagFld</var> | |||
| The name of the table field to store the extracted element tags. | |||
|- | |||
| <var>attr1Name</var> | |||
| The name of an attribute to extract. | |||
|- | |||
| <var>attr1Fld</var> | |||
| The name of the table field where the <var>attr1Name</var> attribute values should be stored. | |||
|- | |||
| <code>/Recursive</code> | |||
| If specified, the whole sub-tree is extracted. | |||
|- | |||
| <code>/Parent</code> | |||
| If specified, the element's parent's position is stored in the <var>posFld</var> column. | |||
|- | |||
| <code>/1</code> or <code>/All</code> | |||
| If <code>/1</code> is specified, elements are only extracted if ''any'' of the specified attributes are set. If <code>/All</code> is specified, elements are only extracted if ''all'' of the specified attributes are set. The default behaviour is to extract all elements irrespective of whether any attributes are set or not. | |||
|- | |||
| <code>/Y</code> | |||
| If specified, the <var>elemTag</var> argument is treated as a <code>DOCTYPE</code> class name and not only the elements, but also their derived classes are searched (e.g. if <var>elemTag</var> is <code>ASeg</code>, then all <code>APar</code>'s are searched too). | |||
|} | |||
If positions are stored (i.e. <var>posFld</var> is not set to <code>*</code>) the programmer is responsible for deleting the positions. | |||
SET <var>xmlfile</var> EXTRACTTABLE <var>extTable</var> <var>elemTag<sub>1</sub></var> <var>nameFld<sub>1</sub></var> … /Mode=Attributes /Y /Recursive | |||
Saves a list of all the attributes found in the specified elements. The attributes of each element (<var>elemTag<sub>X</sub></var>) are stored in the associated table field <var>nameFld<sub>X</sub></var>. | |||
{| | |||
| <code>/Mode=Attribute</code> | |||
| This is mandatory. | |||
|} | |||
See the command above for a description of the other parameters and options. | See the command above for a description of the other parameters and options. | ||
SET <var>xmlfile</var> EXTRACTTABLE <var>extTable</var> <var>posFld</var>|* <var>tagFld</var> <var>attr1Name</var> <var>attr1Fld</var> … /Mode=Read [/All|Tagged] | |||
Updates the attribute list already in the table <var>extTable</var>. No new elements are searched (i.e. the existing positions are used). | Updates the attribute list already in the table <var>extTable</var>. No new elements are searched (i.e. the existing positions are used). | ||
{| | |||
| <code>/Mode=Read</code> | |||
| This is mandatory. | |||
|- | |||
| <code>/All</code> or <code>/Tagged</code> | |||
| If <code>/All</code> is specified, all table entries are used (this is the default). If <code>/Tagged</code> is specified, then only the tagged entries are used. | |||
|} | |||
See the command above for a description of the other parameters and options. | See the command above for a description of the other parameters and options. | ||
===ROOT=== | ===XML: <code id="ROOT">ROOT</code>=== | ||
SET <var>xmlfile</var> ROOT [<var>*</var>|<var>tag</var>] [<var>aname<var> </var>avalue</var> … ] [/Delete] | |||
Name, rename or delete the root element tag, add, modify or delete the root element's attributes. An attribute is deleted if the value (<var>avalue</var>) passed is empty (''). If a doctype has been defined, the | Name, rename or delete the root element tag, add, modify or delete the root element's attributes. An attribute is deleted if the value (<var>avalue</var>) passed is empty (<code>''</code>>). If a doctype has been defined, the tag and attributes of the root element are validated and the function fails if the parameters are invalid. All required attributes which are not passed are automatically set to their default values. | ||
{| | |||
|- | |||
| <var>tag</var> | |||
| root element tag (e.g. '<code>STxDataSet</code>'). If an asterisk is specified, the root element tag is left unmodifed. | |||
|- | |||
| <var>aname</var> | |||
| An XML attribute name. Used in combination with the <var>avalue</var> parameter, this can set or delete a root element attribute. | |||
|- | |||
| <var>avalue</var> | |||
| A value to assign to the previous <var>aname</var> attribute. You can delete an attribute if this parameter is an empty string (e.g. <code>$#file root * CH ''</code>) | |||
|- | |||
| <code>/Delete</code> | |||
| If specified, the root element and all of the contained content is removed. If used in combination with <var>tag</var>, this option deletes the document and then creates a new root element. | |||
|} | |||
Using the <code>ROOT</code> command invalidates all saved positions! | |||
===XML: <code id="SETATTRIBUTE">SETATTRIBUTE</code>=== | |||
SET <var>xmlfile</var> SETATTRIBUTE <var>aname</var> <var>avalue</var> … [/Parent] | |||
Set the attribute <var>aname</var> of the selected element to <var>avalue</var>. If <code>/Parent</code> is specified, the attributes of the parent element are modified instead of those of the selected element. Multiple attribute assignments (pairs of <code><var>aname</var> <var>avalue</var></code>) may be specified. An attribute is removed if an empty value is specified. If a doctype has been defined, the attributes are validated and the function fails if they are invalid. | |||
: | Note: if the function fails, the pre-call state is not guaranteed (some attributes may have been set etc.). | ||
{| | |||
|- <var>aname</var> | |||
| The name of the attribute to set. | |||
|- | |||
| <var>avalue</var> | |||
| The value to set the attribute to. | |||
|} | |||
SET <var>xmlfile</var> SETATTRIBUTE <var>table</var> <var>field</var> <var>aname</var> <var>avalue</var> … | |||
The table <var>table</var> column <var>field</var> contains the positions of the elements who's attributes should be set. | The table <var>table</var> column <var>field</var> contains the positions of the elements who's attributes should be set. | ||
{| | |||
|- | |||
| <var>table</var> | |||
| The table item containing the positions of the elements where attribute should be set. | |||
|- | |||
| <var>field</var> | |||
| The table item field where element positions are stored. | |||
|- | |||
| <code>/Resetpos</code> | |||
| All element positions will be deleted after use. | |||
|- | |||
| <code>/All</code> | |||
| All table entries will be used. This is the default. | |||
|- | |||
| <code>/Tagged</code> | |||
| Only tagged entries will be used. | |||
|- | |||
| <code>/Value</code> | |||
| The <var>avalue</var> arguments are attribute values. | |||
|- | |||
| <code>/Fieldid</code> | |||
| The <var>avalue</var> arguments are table field names which contain attribute values. | |||
|} | |||
SET <var>xmlfile</var> SETATTRIBUTE <var>tag</var> <var>aname</var> <var>avalue</var> … [/Y] [/Recursive] | |||
Set all the attributes of <var>tag</var> elements on the current level. | Set all the attributes of <var>tag</var> elements on the current level. | ||
{| | |||
|- | |||
| <var>tag</var> | |||
| The tag identifying the elements to modify. | |||
|- | |||
| <code>/Y</code> | |||
| If the <code>/Y</code> option is used, the <var>tag</var> argument is used as a <code>DOCTYPE</code> class name, not an element tag. All derived classes are set too. | |||
|- | |||
| <code>/Recursive</code> | |||
| If specified, the command is carried out on the sub-tree as well. | |||
|} | |||
: | ===XML: <code id="SORT">SORT</code>=== | ||
SET <var>xmlfile</var> SORT [<var>attrID<sub>0</sub></var> <var>dir<sub>0</sub></var> <var>attriID<sub>N</sub></var> <var>dir<sub>N</sub></var>] [/Delete] | |||
Sort the children of the selected element according to the given attributes and directions and set the element's <code>sort</code> attribute. Previous sort attributes are overwritten. Calling this function without parameters re-sorts using the existing attributes. Calling the function without parameters but with the <code>/Delete</code> option removes the sort attributes. This function only supports attributes defined in the doctype. Note that if one of the attributes is unique (as defined in the doctype definition), only this attribute will be used to sort. | |||
{| | |||
|- | |||
| <var>attrId</var> | |||
| The name of an attribute defined in the doctype. | |||
|- | |||
| <var>dir</var> | |||
| The direction in which the elements should be sorted. The following values are allowed: <code>Ascending</code> and <code>Descending</code> (and any shorter version thereof, e.g. <code>Asc</code> or <code>Desc</code> or <code>a</code> or <code>d</code>) as well as <code>0</code> and <code>1</code> | |||
|- | |||
| <code>/Delete</code> | |||
| If no parameters are passed, the existing sort attributes are deleted. | |||
|} | |||
:If | The internal implementation works in the following way: | ||
;Unique Attributes: If one of the attributes passed to the <code>SORT</code> command is unique (as defined in the doctype), only this attribute is used for sorting. The elements are then sorted according to the direction and case is respected, if so defined in the doctype. All elements added to this level after sorting are added at the correct sorted position. Changing attributes of sorted elements also rearranges the sort order. If you have a large number of segments in an <code>AFile</code>, sorting according to a unique attribute is highly recommended, since the performance of the dataset validation is very bad for unsorted unique attributes. If you set the parent <code>sort</code> attribute by hand and want the sort to happen automatically, please set the <code>unsorted</code> attribute to <code>1</code>. Now the next time an attribute is changed, or an element is added, all elements will first be sorted. | |||
;Non-unique Attributes: If the sort attributes are not unique, multiple attributes can be used. Elements added after sorting are not inserted at the correct position; instead, a further attribute <code>unsorted</code> is set in the parent element. Changing attributes after sorting does not affect the sort order – the parent attribute <code>unsorted</code> is set. | |||
; Validation: The <code>VALIDATE</code> command checks for sort attributes and sorts the elements before validation. When closing {{STX}}, the DataSet is validated, and therefore all elements with sort attributes are sorted. | |||
=== | ==== Examples ==== | ||
$#xmlfile SORT ID Asc | |||
The children of the selected element are sorted by their ID attribute in ascending order. The following command does the same by means of the SETATTRIBUTE command: | |||
SET $#xmlfile SETATTRIBUTE sort 'ID Asc' unsorted '1' | |||
When the selected element of <code>$#xmlfile</code> is an AFile, all ASegs in this AFile will be sorted according to their ID. Sorting will happen automatically, either on modification/addition of an element or attribute to one of the ASegs, or on validation. | |||
==XML Element Data Manipulation== | ==XML Element Data Manipulation== | ||
Line 761: | Line 701: | ||
Note: You cannot store data in the data section of an element with children! | Note: You cannot store data in the data section of an element with children! | ||
===GETDATA=== | ===XML: <code id="GETDATA">GETDATA</code>=== <!-- C.G. headings must be unique! --> | ||
SET <var>xmlfile</var> GETDATA <var>varname</var> | |||
Copy contents of XML data section into variable <var>varname</var>. | Copy contents of XML data section into variable <var>varname</var>. | ||
SET <var>xmlfile</var> GETDATA /Table <var>table</var> /Read | |||
Empty table and copy contents of the XML data section into the table item <var>table</var>. This command loads data stored in the format generated by the command | Empty table and copy contents of the XML data section into the table item <var>table</var>. This command loads data stored in the format generated by the command <code>SET $#xmlfile SETDATA /T $#table</code>. | ||
SET <var>xmlfile</var> GETDATA /Table <var>table</var> [ <var>firstField</var> <var>nFields</var> ] /Numeric [/Vector] | |||
Empty the table item <var>table</var> and copy the contents of the selected element | Empty the table item <var>table</var> and copy the contents of the data section of the selected element into the numeric fields of the table. The <code>GETDATA</code> command loads data stored in the format set by the command <code>SET $#xmlfile SETDATA /T/N $#table $#firstField $#nFields</code>. Furthermore, it uses the attributes <code>dim</code> and <code>vector</code> set by the <code>SETDATA</code> command to ascertain the format of the data section. If the option <code>/Vector</code> is specified (see [[Programmer_Guide/Shell_Items/File/SET_FILE#SETDATA|<code>SETDATA</code>]] below), it overrides the corresponding <code>vector</code> attribute if it exists. | ||
===SETDATA=== | ===XML: <code id="SETDATA">SETDATA</code>=== <!-- C.G. headings must be unique! --> | ||
SET <var>xmlfile</var> SETDATA <var>string</var> [ /CData ] | |||
{| | |||
|- | |||
| <var>string</var> | |||
| The string to save in the element. | |||
|} | |||
Set the data of the selected element to <var>string</var>. An empty string can be used to remove data (leading to an empty element). If the <var>string</var> contains characters which are reserved in the XML specification (e.g. <, >, &), the option <code>/CData</code> must be used, which will create a <code>CData</code> section. | |||
SET <var>xmlfile</var> SETDATA /Table <var>table</var> [ /CData ] | |||
{| | |||
| <var>table</var> | |||
| The table containing the data to be stored in the element. | |||
|- | |||
| <code>/Table</code> | |||
| A mandatory option. | |||
|} | |||
Store the content of <var>table</var> in the data section of the selected element (note: this is different from <code>ADDTABLE</code>, which adds one element per entry). The write format of the table is always used (see [[Programmer_Guide/Shell_Items/Table/SET_TABLE#FORMAT|<code>SET table FORMAT</code>]]). If <var>table</var> contains characters which are reserved in the XML specification, the option <code>/CData</code> must be used. | |||
SET <var>xmlfile</var> SETDATA /Table <var>table</var> [ <var>firstField</var> <var>nfields</var> ] /Numeric [ /Vector ] | |||
{| | |||
|- | |||
| <var>firstField</var> | |||
| The first field to extract data from. | |||
|- | |||
| <var>nFields</var> | |||
| The number of consecutive fields to extract data from. | |||
|- | |||
| <code>/Numeric</code> | |||
| A mandatory option. | |||
|} | |||
Store the contents of <var>table</var> in the data section of the selected element. The <var>table</var> must be an [[Programmer_Guide/Shell_Items/Table/Introducing_Table_Items#Extended_Table|extended table]] and the selected fields must be numeric! The values are stored as decimal numbers. The data is stored row-by-row (if no additional option is supplied) or column-by-column (if option <code>/Vector</code> is given). The attribute <code>dim</code> is automatically added to the selected element with the values <code>"nRows nColumns"</code>. If the option <code>/Vector</code> is specified, the attribute <code>vector</code> is added with the value <code>"1"</code>. | |||
Store the contents of <var>table</var> in the data section of the selected element. The <var>table</var> must be an extended table and the selected fields must be numeric! The values are stored as decimal numbers. The data is stored row-by-row (no option) or column-by-column (option /Vector). The attribute <code>dim</code> is automatically added to the selected element with the values <code>"nRows nColumns"</code>. If the option /Vector is specified, the attribute <code>vector</code> is added with the value <code>"1"</code>. | |||
==XML Element Positions== | ==XML Element Positions== | ||
Element positions are unique strings which can be used like | Element positions are unique ID strings which can be used like pointers or references to an element. The position of an element is saved with the command "<code><var>#posvar</var> := POSITION $<var>#file</var></code>" (see the command [[Programmer_Guide/Command_Reference/POSITION|<code>POSITION</code>]]). | ||
===POSITION=== | ===XML: <code id="POSITION">POSITION</code>=== | ||
< | SET <var>xmlfile</var> POSITION [ <var>parameters</var> … ] [ [[Programmer_Guide/Command_Reference_Options/Silent|/Silent]] ] | ||
All <code>POSITION</code> commands | All <code>POSITION</code> commands support the [[Programmer_Guide/Command_Reference_Options/Silent|<code>/Silent</code> option]]. | ||
SET <var>xmlfile</var> POSITION <var>pos</var> /Restore [ /Silent ] | |||
Select the element at position <var>pos</var> and delete the position. | Select the element at position <var>pos</var> and delete the position. | ||
SET <var>xmlfile</var> POSITION <var>pos</var> /Goto [ /Silent ] | |||
Select the element at position <var>pos</var> but do not delete the position. | Select the element at position <var>pos</var> but do not delete the position. | ||
SET <var>xmlfile</var> POSITION [<var>pos</var>|*] /Delete [/Children] [ /Silent ] | |||
Delete the position identified by <var>pos</var>. If <var>pos</var> is empty or an asterisk, then all saved positions for the selected element are deleted. If the option /Children is used, this | Delete the position identified by <var>pos</var>. If <var>pos</var> is empty or an asterisk, then ''all'' saved positions for the selected element are deleted. If the option <code>/Children</code> is used, this position deletion is carried out recursively. | ||
SET <var>xmlfile</var> POSITION <var>pos<sub>1</sub></var> [<var>pos<sub>2</sub></var>] /Equal [ /Silent ] | |||
Tests if the two positions <var> | Tests if the two positions <var>pos<sub>1</sub></var> and <var>pos<sub>2</sub></var> reference the same element (<code>RC=0</code> for same element, <code>RC=1</code> for different elements). If only one position (<var>pos<sub>1</sub></var>) is passed, this position is compared with that of the selected element. | ||
==XML Load & Save== | ==XML Load & Save== | ||
===LOAD=== | === XML: <code>LOAD</code>=== <!-- C.G. headings must be unique! --> | ||
SET <var>xmlfile</var> LOAD [<var>path</var>] | |||
Load the document from the last selected or specified path and select the root element (previous content/position information is lost). If a <var>path</var> is specified, data are loaded from path and it is stored for later use, otherwise the stored path is used. The current content and all position and state settings are cleared before loading | Load the document from the last selected or specified path and select the root element (previous content/position information is lost). If a <var>path</var> is specified, data are loaded from path and it is stored for later use, otherwise the stored path is used. The current content and all position and state settings are cleared before loading. | ||
The function sets <var>RC</var> to <samp>0</samp> on success. | |||
=== XML: SAVE=== <!-- C.G. headings must be unique! --> | |||
SET <var>xmlfile</var> SAVE [<var>path</var>] | |||
Store (i.e., save to disk) the document in the supplied <var>path</var> or, if none is supplied, in the last selected path. If <var>path</var> is specified, it is also stored for later use. | |||
==XML Navigation And Searching== | |||
The following general navigation options can be supplied with any of the navigation, search and data processing command: | |||
* <code>/In</code> step into the selected element: set the selected element to the parent element and its first child to the selected element; this option is applied after successful execution of the navigation or manipulation function | |||
* <code>/Out</code> step out of the parent: set the element containing the current parent to the new parent and the current parent to the selected element; this option is applied before the function is executed | |||
* <code>/First</code>, <code>/Last</code> and <code>/Next</code> set the position to the first or last element of the current section (<code>/First</code> or <code>/Last</code>) or continue navigation/search (<code>/Next</code>); these options are applied ''before'' the respective function is executed (but ''after'' the <code>/Out</code> option). | |||
* <code>/nodetype</code> selects the type of the node to be found; the types /Element, /Processinginstruction, /Comment and /Doctype are supported | |||
===XML: <code id="Find_2">FIND</code>=== | |||
SET <var>xmlfile</var> FIND | |||
The <code>FIND</code> command searches an XML file for one, or more, occurences of a certain node. There are two variants of using the command: | |||
* consecutively searching for the first (<code>SET <var>xmlfile</var> FIND /First</code>), and any further occurence (<code>SET <var>xmlfile</var> FIND /Next</code>); or | * consecutively searching for the first (<code>SET <var>xmlfile</var> FIND /First</code>), and any further occurence (<code>SET <var>xmlfile</var> FIND /Next</code>); or | ||
* searching for all occurrences in a single operation, returning them in an {{STX}} table (SET <var>xmlfile</var> FIND <var>tableitem</var>…) | * searching for ''all'' occurrences in a single operation, returning them in an {{STX}} table (<code>SET <var>xmlfile</var> FIND <var>tableitem</var>…</code>) | ||
==== Consecutive <code>FIND</code> operations ==== | |||
Search for a node of the selected type (/ | SET <var>xmlfile</var> FIND <var>*</var>|<var>tag</var> [ [[#cexpr|<var>cexpr</var>]] [ [[Programmer_Guide/Concepts/Conditional_Expressions#loper|<var>loper</var>]] …]] [/In|Out /First|Next] [/Element|Processinginstruction|Doctype] [/Y] | ||
Search for a node of the selected type (<code>/Element</code> which is the default, <code>/Processinginstruction</code>, <code>/Doctype</code>, see [[Programmer_Guide/Shell_Items/File/SET_FILE#GOTO|<code>SET file GOTO</code>)]] with the tag <var>*</var> or <var>tag</var> on the level of the selected element. For nodes of type ''element'' the arguments <var>cexpr</var> (conditional expression for attribute values, see the [[#cexpr|table below]] and <var>loper</var> ([[Conditional_Expressions#loper|logical operator]]<!-- WTF? -->) are formatted and processed similarly to the [[Programmer_Guide/Shell_Items/Table/SET_TABLE#FIND|<code>SET table</code> <code>FIND</code>]] function (e.g. <code>attributename:<=:1000</code> or <code>attributename:=I:a*.0*</code>). Use the option <code>/First</code> (default) to begin search at the first element in the section, and <code>/Next</code> to start with the element following the selected element. If the node is found, it is selected, otherwise the selection remains unaffected. If the option <code>/Y</code> is specified, then <var>tag</var> is treated as a <code>DOCTYPE</code> class name, rather than an XML element tag (this means derived types are also recognised). | |||
The shell variable <code>RC</code> is set to the integer <code>7</code> if the command was syntactically correct, but no element was found. The shell variable <code>RC</code> is set to the integer value <code>0</code> if an element corresponding to the search criteria was found. | The shell variable <code>RC</code> is set to the integer <code>7</code> if the command was syntactically correct, but no element was found. The shell variable <code>RC</code> is set to the integer value <code>0</code> if an element corresponding to the search criteria was found. | ||
Find and delete the first element on the current level | ===== Example ===== | ||
Find and delete the first element on the current level that has an <code>ID</code> attribute with a value of <code>3</code>: | |||
$#f find * 'ID:==:3' /First | $#f find * 'ID:==:3' /First | ||
if '$rc' == | if '$rc' == 0 $#f deleteelement | ||
==== Returning all results in a table ==== | |||
SET <var>xmlfile</var> FIND <var>postable</var> <var>posfield</var> <var>tag</var> [<var>cexpr</var> [<var>loper</var> <var>cexpr</var>…]…] [/Recursive /Y] | SET <var>xmlfile</var> FIND <var>postable</var> <var>posfield</var> <var>tag</var> [ [[#cexpr|<var>cexpr</var>]] [ [[Programmer_Guide/Concepts/Conditional_Expressions#loper|<var>loper</var>]] [[#cexpr|<var>cexpr</var>]] …]…] [/Recursive /Y] | ||
Like the above <code>FIND</code> commands, except that the command does not return when it finds the first match, rather it saves the position of all matching elements in one field (<var>posfield</var>) of the specified table (<var>postable</var>). If the option / | Like the above <code>FIND</code> commands, except that the command does not return when it finds the first match, rather it saves the position of ''all'' matching elements in ''one'' field (<var>posfield</var>) of the specified table (<var>postable</var>). If the option <code>/Recursive</code> is specified, the whole sub-tree is searched. If the option <code>/Y</code> is specified, the <var>tag</var> string is treated as a <code>DOCTYPE</code> class name rather than an element tag, and all derived classes are searched. | ||
{| | |||
|- | |||
| <var>posTable</var> | |||
| The extended table where to store element positions. | |||
|- | |||
| <var>posField</var> | |||
| The extended table field in which to store element positions. | |||
|} | |||
For all other parameters, please see the [[#Consecutive FIND operations|consecutive variant of the <code>FIND</code>]] command (above), and the [[#cexpr|table of <code>cexpr</code> expressions]] (below). | |||
===== Example ===== | |||
// find all elements with a specific numerical attribute value | // find all elements with a specific numerical attribute value | ||
$#f find $#t $#tField $#elem '$#elemAttr:==:$#elemattrvalue' /Recursive | $#f find $#t $#tField $#elem '$#elemAttr:==:$#elemattrvalue' /Recursive | ||
==== <span id="Conditions"><span id="cexpr">Find Conditions</span></span> ==== | |||
{| | {| | ||
|- | |- | ||
Line 940: | Line 891: | ||
|} | |} | ||
===XML: <code id="GOTO">GOTO</code>=== | |||
SET <var>xmlfile</var> GOTO [<var>epath</var>] [/First|Next|Last] [/In|Out] [/Element|Comment|Processinginstruction|Doctype] [/Reset] | |||
<code> | Go to the first (<code>/First</code>, last (<code>/Last</code>) or next (<code>/Next</code>) element. If <var>epath</var> is specified, go to the first (<code>/First</code>, last (<code>/Last</code>) or next (<code>/Next</code>) element matching <var>epath</var>. | ||
You can specify the type of node to navigate to with the options <code>/Element</code>, <code>/Comment</code>, <code>/Processinginstruction</code> and <code>/Doctype</code>, respectively. If only the node type option is used (without argument and other options), the first node of the respective type in the document is located. | |||
The options <code>/First</code>, <code>/Next</code> and <code>/Last</code> only work with <var>epath</var> if <var>epath</var> does not contain slashes, i.e. if it specifies an element tag without an actual path (e.g. "<code>elemtag</code>"). For multi-level <var>epaths</var> like '<code>*/elemtag</code>' or '<code>/root/elemtag/elemtag</code>', the search finds the ''first'' element every time, and neither of <code>/First</code>, <code>/Next</code> and <code>/Last</code> should be supplied. | |||
{| | |||
|- | |||
| <var>epath</var> | |||
| The path of the element to go to. The normal format of <var>epath</var> is "<code>elemtag</code>". If you want to go to an element on a deeper level, the format is '<code>*/elemtag</code>'. The format of <var>epath</var> is absolute if it starts with the forward slash (e.g. '<code>/rootelem/firstelem</code>'). To ensure that <var>epath</var> is correctly interpreted, always enclose it in single quotation marks. XML is case sensitive, so <var>epath</var> must match exactly (wildcards are not supported). If no options are given, the current position is reset to the first child element of the root element. | |||
|- | |||
| <code>/First</code>, <code>/Next</code> or <code>/Last</code> | |||
| Determines whether to navigate to the first, last or next element. The default is <code>/Next</code>. | |||
|- | |||
| <code>/E</code> || Navigate to a data element node (e.g. <code><elemtag></code>) | |||
|- | |||
| <code>/C</code> || Navigate to an XML comment (e.g. <code><!-- comment --></code>). The argument <var>epath</var> is ignored. | |||
|- | |||
| <code>/P</code> || Navigate to an XML processing instruction (e.g. <code><?pinst …?></code>). The argument <var>epath</var> is used as the tag name of the processing instruction node. | |||
|- | |||
| <code>/Doctype</code> || Navigate to a document type (e.g. <code><!DOCTYPE typename …></code>). The argument <var>epath</var> is used for the name of the document type. The default is <code>/Element</code>. | |||
|- | |||
| <code>/Reset</code> | |||
| Reset the element selection. This means that no element is selected and a GOTO command with the option /Next will navigate to the first element. | |||
|- | |||
| <code>/In</code> | |||
| step into the selected element: set the selected element to the parent element and its first child to the selected element; this option is applied after successful execution of the navigation or manipulation function | |||
|- | |||
| <code>/Out</code> | |||
| step out of the parent: set the element containing the current parent to the new parent and the current parent to the selected element; this option is applied before the function is executed | |||
|} | |||
Note that you can get yourself into difficulties if you use multiple options, e.g <code>/i /f</code>. Although you may feel inclined to think you are going to navigate ''in'' and go to the ''first'' element there, you will actually go to the first element and then navigate in. | |||
You can use the [[Programmer Guide/Shell Items/File/FILE Item Attributes|file item attribute]] <code>!XCHILDREN</code> to determine if an element has children or not. | |||
<var>RC</var> is set to <samp>0</samp> if the element is found and a value greater than 0 if not. | |||
==== Example ==== | |||
// go to the root element <STxColorPalette> | // go to the root element <STxColorPalette> | ||
$#xmlfile goto '/STxColorPalette' | $#xmlfile goto '/STxColorPalette' | ||
Latest revision as of 09:55, 24 June 2019
File Item | ||||
---|---|---|---|---|
INTRODUCING | NEW | SET | ATTRIBUTES | EXAMPLES |
Contents
Binary File Commands
Binary Files: LIST
SET bfile LIST table
table | A simple table. |
Append one entry per binary file section to the table table. Each entry contains the size of the section value, the number of rows and columns, and the data type in the following format:
1|…|4 rows columns I16|I32|F32|F64
Binary Files: LOAD
SET bfile LOAD numitem section
numitem | The id of a numeric shell item. The format and type of this item is changed to match the requirements of the loaded section. |
section | The index of the section to load. |
Load a section from a binary file into a numeric shell item.
Binary Files: SAVE
SET bfile SAVE numitem [ section ] [ /1|2|3|4]
numitem | The id of a numeric shell item or an asterisk. If numitem is an asterisk and section ≥ 0, then the section is deleted. If numitem is an asterisk and section = -1 then all sections are deleted.
|
section | The section index (0 ,1 ,…) of an existing section. Leave empty to append a section.
|
/n
|
For a new section, this option determines the format of the section: /1…I16, /2…I32, /3…F32, /4…F64 (the latter is the default). Note that this flag is ignored if the section already exists. |
Save the numerical item data to a binary file section. If the section already exists, then the numerical data must be the same size as the section data (i.e. the same number of rows and columns).
You can delete an existing section with the command bfile SAVE * section
. If section equals -1
, all sections are deleted.
Finding Files on Disk
Finding Files: FIND
SET file FIND search [ /File | /Directory ]
The command FIND
starts a new search for files or directories located in the current directory and matching the search string (a file or directory name containing normal Windows wildcards).
The command NEXT
looks for the next file matching the search specified in the FIND
command. Both commands return an error if no (more) matching files were found. If the return code (RC) is zero, a matching file was found and its name etc. can be accessed via the file item attributes. The file item file must be a list file item (see NEW FILE
).
search | file or directory name to search for. |
/File or /Directory
|
If the option /F is specified, files are searched for, if /D is specified, directories are searched for. The default is /F .
|
Finding Files: NEXT
SET file NEXT
The command NEXT
looks for the next directory or file matching the search string specified in the FIND
command (q.v.)
Status File Commands
These commands can be applied to a file system file item (also called dummy file item).
Status Files: STATUS
SET file STATUS path [ /Silent ]
Retrieve the status of file path. If the file path exists (on disk), all available status values are retrieved and can be accessed via the file-item attributes. The file item file must be of type file.
/Silent
|
If specified, errors will generate warning messages rather than error messages. See The Silent Flag for details. |
Status Files: DELETE
SET file DELETE path [ /Silent ]
Delete the file path. The command will fail if file is not an actual file (but a directory, a file system file item, or the like).
/Silent
|
If specified, errors will generate warning messages rather than error messages. See The Silent Flag for details. |
Status Files: RENAME
and COPY
SET file RENAME|COPY path newpath [ /Silent ]
Rename or copy the file path. The file item file must be a file system file item (as opposed to a directory, a file system file item, and the like). The RENAME
function can also be used to move a file into another directory or to another disk drive or network-directory (located on another computer). Note that the RENAME
command will fail if the newpath already exists, whilst the COPY
command will silently overwrite an existing target file.
/Silent
|
If specified, errors will generate warning messages rather than error messages. See The Silent Flag for details. |
Text and Section File I/O
The SET FILE
commands LIST
, LOAD
and SAVE
access the content of files attached to file items of type TEXT
or SECTION
(see NEW FILE … /Text
and NEW FILE … /Section
). Note that you can also use the command WRITE
to write data to a file item.
SET file cmd table [type name]
cmd | Either LIST , LOAD or SAVE (see below).
|
table | A table to load data into or read data from. |
type | Either TEXT or SECTION.
|
name | A section name. |
A section is defined by its type and a name, the latter being optional if there is only one section of the same type. Both are strings which may not contain the characters "$
", "[
" , "]
", ";
" or "'
" (single quotes). The name may consist of more than one word.
Note that the mode in which the file is read or written is dependent on the flags passed to the NEW FILE
command.
Text Files: LIST
SET file LIST table [ type|* name|* ]
Retrieve a list of sections from a section file (not applicable for other file item types). One table entry with the following format is created per section:
sectionType sectionName
table | The simple table to append the section list to. |
type | The type of sections to list. If no type or an asterisk is specified , all sections are listed. |
name | The name of the sections to list. If no name or an asterisk is specified, all sections of type type are listed. |
Text Files: LOAD
The file item LOAD
command loads the contents of a file into a table. Both LOAD variants support the /Silent option.
SET file LOAD table [ /Silent ] // text file SET file LOAD table type name [ /Silent ] // section file
Load the whole content of the file (in case of a text file) or of a section (in case of a section file), and append the loaded data to the table item table. If the table is an extended or a parameter table, please use the table FORMAT
command to appropriately configure the input formatting options first.
table | A simple, extended or parameter table which will have data appended to it. |
type | The section type to load. There is no default. |
name | The name of the section to load. There is no default. |
/Silent
|
If specified, errors will generate warning messages rather than error messages. See The Silent Flag for details. |
Note that you can load a CSV file by setting the delimiter of the table you are loading into. See Formatting_table_fields.
See load_a_file_into_a_table.sts
in the script examples directory for a working example.
Text Files: SAVE
Save the contents of a shell table item into a file.
SET textFile SAVE table [ /Silent ]
Saves the content of the table item table to a TEXT
file.
table | The table containing the text to save to file. |
/Silent
|
If specified, errors will generate warning messages rather than error messages. See The Silent Flag for details. |
SET sectionFile SAVE table type [name] [ /Silent ]
Saves the content of the table item table to a section name of type type in a section file. Saving an empty table to a section will delete the section.
table | The table containing the text to save to file. |
type | The type of the section (e.g. the section [macro myTestMacro] has the type macro ). This parameter is mandatory.
|
name | The name of the section (e.g. the section [macro myTestMacro] has the name myTestMacro ).
|
/Silent
|
If specified, errors will generate warning messages rather than error messages. See The Silent Flag for details. |
Text Files: SYNC
SET file SYNC
Write section file from memory to disk.
Locking / Unlocking File Items
The use of lock/unlock is only important, if a file item is (or may be) used by more than one thread. In STx shells, spu items and display item are running in their own thread.
SET file LOCK
Lock the file item file. The execution of the calling shell is stopped, until the file item can be locked. If locked, only the shell which locked it has access to its content. The file must be explicitly unlocked with the command UNLOCK
. Always beware deadlocks.
SET file LOCK timeout
Try to lock the file item file, but wait only the specified time. This command returns 0 (success) if the lock request was successful within the timeout, and a non-zero error code if not. If the caller already holds the lock, the command will fail immediately. This makes sense because, since the caller is the owner, it cannot release it whilst its waiting. The argument timeout specifies the maximum lock-timeout in milliseconds and must be a number greater than zero.
SET file UNLOCK
Unlock the file item file. Note: Its very important that for each successful LOCK
an UNLOCK
is called!
XML Doctype
The STx XML implementation supports an element type definition which is not directly compatible with the standard XML definition methods like DTD or XML Schema. If necessary we will add an interface to a standard in the future. The XML element definitions are created with the command SET xmlfile DOCTYPE …
as documented below. All definition commands should be applied before the XML content is accessed. The sequence of definition commands must be finished with the command SET xmlfile DOCTYPE CLOSE
to verify and initialize the element types. The element type definitions are not mandatory. They are applied during XML access only if available.
The following notes apply to the commands below:
- If an element is derived from a parent element, it inherits all children, all attributes and the base and not-base element. All inherited definitions can be overridden in the derived element.
- If a base element is defined, elements of type tag can only be added to a position below (inside) the base element or an element derived from the base element.
- If a none-base element is defined, elements of type tag can not be added to a position below (inside) the none-base element or an element derived from the none-base element.
- If an undefined element tag is used as argument (e.g. parent, base or in the child command) an element type tag is created automatically (and should be selected and configured later).
- If children are set to invisible, all element below/inside the element are hidden
- The default attribute visibility is used for undefined attributes and for attributes without visibility setting.
- A valid definition sequence (i.e., the sequence of all
DOCTYPE
commands beforeDOCTYPE CLOSE
) must consist of at least one element definition and the root and name assignment.
STx has a predefined DOCTYPE
(defined in the stxconfig.xml
file), which guarantees data integrity.
// A very basic doctype example $#xml doctype name 'testdoctype' $#xml doctype element root * * * * yes yes yes $#xml doctype root root $#xml doctype element elem * * * * yes yes yes $#xml doctype attribute type yes all default string no yes $#xml doctype close
DOCTYPE ELEMENT
SET xmlfile DOCTYPE ELEMENT tag [parent base nobase data vtag vchildren vattributes]
Create a new element type or select an element type (e.g. to define children or attributes). See Note 7.
tag | tag name of the element type |
parent | tag name of the parent type or * if none (1) (4)
|
base | tag name of the base element or * (2) (4)
|
nobase | tag name of the not-base element or * (3) (4)
|
data | a string defining the type of the data section (currently unused) |
vtag | show tag in dialogs (no > or yes )
|
vchildren | show children in dialogs (no > or yes ) (5)
|
vattributes | default visibility of attributes in dialogs (no >, yes or all ) (6)
|
DOCTYPE CHILD
SET xmlfile DOCTYPE CHILD tag minoccur maxoccur
Add a child element definition to the last created/selected element.
tag | tag name of the child element (4) |
minoccur | minimum number of occurrences (must be ≥ 0 or * meaning 0 occurences)
|
maxoccur | maximum number of occurrences (must be ≥ minoccur or * meaning ℵ0)
|
DOCTYPE ROOT
SET xmlfile DOCTYPE ROOT tag
Assign the type tag of the root element. The element type must have been defined (7).
DOCTYPE NAME
SET xmlfile DOCTYPE NAME anytext (7)
Assign the title/name of the element definition (7).
DOCTYPE CLOSE
SET xmlfile DOCTYPE CLOSE
Close definition sequence. Initialise and verify all types. This must be the last command of the definition sequence (7).
VALIDATE
SET xmlfile VALIDATE errorTable|* [testdoc /Insert] [/Recursive] [/Position /Children /Attributes] [/Showposition]
Validate the xmlfile's selected element using the defined doctype. If all tests are passed, or if no doctype is defined, it sets RC to 0. A simple table (errorTable) can be passed, to log errors in. The tests can be performed on either just the selected element or the selected element and all elements within it (/Recursive
). The position (/Position
), attributes (/Attributes
) and the occurrence of children (/Children
) can be tested. If a test document (testdoc) is passed, the test document's selected element is validated (instead of the xmlfile) using the xmlfile's doctype. If the option /Insert
is used in conjunction with testdoc, the test document's selected element is validated as if it were inserted at the position of the xmlfile's selected element. If no options are given, the options /R/P/C/A
are used by default. The option /Showposition
modifies any error strings, prefixing the string with a position id (leading to e.g. "e;P#54 ASeg has invalid attributes
"e;).
errorTable | A simple table in which to log errors. |
testdoc | An XML shell-file to be tested against the defined DOCTYPE. |
XML Element and Attribute Manipulation
All commands act on the selected element unless otherwise indicated. On loading an XML file, the selected element is set to the root element. Navigating through the file then selects different elements.
XML: ADDELEMENT
SET xmlfile ADDELEMENT ename|xmlSourceFile [aname avalue …] [/Before|After|Replace /In|Out /First|Last /Copy]
Create a new empty element with tag ename.
The element is inserted before (/Before
) or after (/After
, which is the default) the selected element of xmlfile or it replaces (/Replace
) the selected element. Attribute assignments (aname avalue
) can be specified to set element attributes on the fly.
If a doctype has been defined, the element's position and attributes are validated and the function fails if the parameters are invalid. Required attributes which were not passed are set to their default values.
When the option /Copy
is used in conjunction with an xmlSourceFile (instead of an ename), the selected element of xmlSourceFile is added.
The navigation options are applied as follows: The option /Out
is carried out before adding the element. The options /First
or /Last
are then performed. After the element is added, the /In
option is carried out.
XML: ADDFILE
SET xmlfile ADDFILE source [/After|Before|Replace] [/In|Out] [/Delete] [/Children] [/Novalidate]
Copy the selected element from XML file-item source to xmlfile. The element is inserted before (/Before
) or after (/After
which is the default) the selected element of xmlfile, or it replaces the selected element (/Replace
). If the option /Delete
is specified, the copied element is removed from source and the next (source) element (if any) is selected. If no navigation option is specified, the added element is selected. Possible navigation options are /In
(step into the added element, after add) and /Out
(step out of current parent, before add).
source | The source XML file item to be added. |
/After , /Before or /Replace
|
Insert the source file after or before the selected element, or replace the selected element. |
/In or Out
|
Navigate out of the selected xmlfile element before add or navigate into the xmlfile selected element after add. |
/Delete
|
Delete the sources selected element from the source file once it has been added. |
/Children
|
If this flag is specified, all children of the current source element are added to the current element of the target file (as children). In this case all other options except /Novalidate are ignored!
|
/Novalidate
|
Disable validation (do not validate source data) |
- Note that if adding the file at root level, the root element will be replaced no matter what
/A
,/B
and/R
options are given. - Note that if the root element of the source document is added, the nodes on that level (e.g. the
<?xml?>
and<!DOCTYPE>
entries) are not copied.
This function sets RC to 0 on success.
XML: DOCTYPE ATTRIBUTE
SET xmlfile DOCTYPE ATTRIBUTE name required visibility default type params
Add an attribute definition to the last created/selected element.
name | attribute name | ||||||||||
required | attribute is required (yes or no )
| ||||||||||
visibility | visibility of attribute in dialogs (no …hidden, yes …show value, all …show name and value)
| ||||||||||
default | default value or * for no default
| ||||||||||
type, params | attribute data type and configuration parameters:
| ||||||||||
minimum | minimum value or * for infinite
| ||||||||||
maximum | maximum value or * for infinite
| ||||||||||
respectcase | respect (yes ) or ignore (no ) case in search/compare functions
| ||||||||||
unique | value must be unique (yes ) on the elements level or not (no )
| ||||||||||
value1, value2 | possible values for a valuelist attribute |
XML: ADDNODE
SET xmlfile ADDNODE text [aname avalue …] /Comment|DocType|Element|ProcInst [/Before|After|Replace /In|Out /First|Last]
Add a node to the XML-file. The node types supported are processing instructions (<?xml version="1.0"?>
), elements (<item>data</item>), document types (<!DOCTYPE section SYSTEM "stx.dtd">
) and comments (<!—comment -->
). The text has a different meaning for each node type: for a processing instruction it is the target xml, for an element it is the tag item, for the document type it is the text between "<!DOCTYPE
" and ">
" and for a comment it is the text within the comment markers. Element nodes may be assigned attributes (aname avalue
). The options /First
and /Last
navigate to the first or last node on this level (independent of the node type being added). If a doctype has been defined and the node is an element, the element's position and attributes are validated and the function fails if the parameters are invalid.
XML: ADDTABLE
SET xmlfile ADDTABLE table ename [/After|Before|Replace] [/In|Out /Data|Empty /Cdata] [/TagErrorsOnly]
Add the entries of table as elements to xmlfile. One element per entry is added, after (/After
, which is the default) or before (/Before
) the current element, or replacing (/Replace
) the current element. The argument ename is used as the element tag. If /Data
is specified, the entry data is stored in the element's data section using the table's write format, otherwise (/Empty
is the default), the entry data is stored as element attributes (use field names as attribute names, does not store empty fields, uses the write format) and the element data section is empty. In conjunction with /Data
, the option /Cdata
can be used to create CData sections instead of normal data sections. There is a severe performance hit (1.300%) if you use the /Before
option since indexes have to be recalculated.
table | A shell table with the entries to be added to the XML file. This parameter is mandatory. |
ename | The string to be used as the created element's tag. This parameter is mandatory. |
/After , /Before or /Replace
|
Specify whether the new elements should be added before (/Before ) or after (/A ) the selected element or if they even should replace the selected element (/Replace ).
|
/In or Out
|
If specified, /In navigates into the selected element before the new element is added. If specified, /Out navigates out of the selected element after the new element has been added.
|
/Data or /Empty
|
If /Data is specified, then the entry is stored in the data section of the new element. Otherwise, the data is stored as attribute values.
|
/Cdata
|
Specify /Cdata if the data should be enclosed within a CData section.
|
/TagErrorsOnly
|
Specify if entries which cause errors should be tagged in the table but correct entries should be added. Otherwise, if one error occurs, no entries are added. |
XML: DELETEELEMENT
SET xmlfile DELETEELEMENT [ename] [/Child]
Delete the selected element itself (no arguments) or delete all elements with the tag ename on the current level. If /Child
is specified, the selected element's children are deleted, but not the selected element itself.
Warning: This operation can take a very long time!
SET xmlfile DELETEELEMENT table field [/Resetpos /Child /All|Tagged]
Delete all elements found at the positions stored in the column field of the table table.
/Child
|
If /Child is specified, the selected element's children are deleted, but not the selected element itself.
|
/Resetpos
|
The positions are deleted, but not the elements. |
/All
|
All table entries are used. This is the default. |
/Tagged
|
Only tagged entries are used. |
XML: EXTRACTFILE
SET xmlfile EXTRACTFILE xmlSubDoc posAttrName [tagN recursiveN … ]
Extract a selection of elements from a source xml file (xmlfile) into a target xml file (xmlSubDoc). The selection is dependent on the parameters tagN and recursiveN and is independent of the selected element. The position of the extracted element in xmlfile is stored in the attribute posAttrName in the extracted element in xmlSubDoc. The original tree structure is retained. If no tagN-names are given, then all positions in xmlSubDoc are removed from xmlfile and the contents of xmlSubDoc are deleted.
Note: the root element is always copied from xmlfile to xmlSubDoc. The pre-call contents (if any) are deleted from xmlSubDoc.
XML: EXTRACTTABLE
There are a number of different flavours of the EXTRACTTABLE
command. The flavour used depends on the use of the /Mode
flag.
SET xmlfile EXTRACTTABLE extTable posFld|* elemTag tagFld attr1Name attr1Fld … [ /P /R /1|All /Y]
Extract a selection of attribute values from elements with a specific tag on the current level into a table.
extTable | The id of an extended table item. |
posFld | The name of the table field where element positions should be stored. If the option /P is specified, the position of the element's parent is save instead.
|
elemTag | The name of the element tag (e.g. "AFile" for <AFile> elements) or an asterisk for all elements. |
tagFld | The name of the table field to store the extracted element tags. |
attr1Name | The name of an attribute to extract. |
attr1Fld | The name of the table field where the attr1Name attribute values should be stored. |
/Recursive
|
If specified, the whole sub-tree is extracted. |
/Parent
|
If specified, the element's parent's position is stored in the posFld column. |
/1 or /All
|
If /1 is specified, elements are only extracted if any of the specified attributes are set. If /All is specified, elements are only extracted if all of the specified attributes are set. The default behaviour is to extract all elements irrespective of whether any attributes are set or not.
|
/Y
|
If specified, the elemTag argument is treated as a DOCTYPE class name and not only the elements, but also their derived classes are searched (e.g. if elemTag is ASeg , then all APar 's are searched too).
|
If positions are stored (i.e. posFld is not set to *
) the programmer is responsible for deleting the positions.
SET xmlfile EXTRACTTABLE extTable elemTag1 nameFld1 … /Mode=Attributes /Y /Recursive
Saves a list of all the attributes found in the specified elements. The attributes of each element (elemTagX) are stored in the associated table field nameFldX.
/Mode=Attribute
|
This is mandatory. |
See the command above for a description of the other parameters and options.
SET xmlfile EXTRACTTABLE extTable posFld|* tagFld attr1Name attr1Fld … /Mode=Read [/All|Tagged]
Updates the attribute list already in the table extTable. No new elements are searched (i.e. the existing positions are used).
/Mode=Read
|
This is mandatory. |
/All or /Tagged
|
If /All is specified, all table entries are used (this is the default). If /Tagged is specified, then only the tagged entries are used.
|
See the command above for a description of the other parameters and options.
XML: ROOT
SET xmlfile ROOT [*|tag] [aname avalue … ] [/Delete]
Name, rename or delete the root element tag, add, modify or delete the root element's attributes. An attribute is deleted if the value (avalue) passed is empty (>). If a doctype has been defined, the tag and attributes of the root element are validated and the function fails if the parameters are invalid. All required attributes which are not passed are automatically set to their default values.
tag | root element tag (e.g. 'STxDataSet '). If an asterisk is specified, the root element tag is left unmodifed.
|
aname | An XML attribute name. Used in combination with the avalue parameter, this can set or delete a root element attribute. |
avalue | A value to assign to the previous aname attribute. You can delete an attribute if this parameter is an empty string (e.g. $#file root * CH )
|
/Delete
|
If specified, the root element and all of the contained content is removed. If used in combination with tag, this option deletes the document and then creates a new root element. |
Using the ROOT
command invalidates all saved positions!
XML: SETATTRIBUTE
SET xmlfile SETATTRIBUTE aname avalue … [/Parent]
Set the attribute aname of the selected element to avalue. If /Parent
is specified, the attributes of the parent element are modified instead of those of the selected element. Multiple attribute assignments (pairs of aname avalue
) may be specified. An attribute is removed if an empty value is specified. If a doctype has been defined, the attributes are validated and the function fails if they are invalid.
Note: if the function fails, the pre-call state is not guaranteed (some attributes may have been set etc.).
The name of the attribute to set. | |
avalue | The value to set the attribute to. |
SET xmlfile SETATTRIBUTE table field aname avalue …
The table table column field contains the positions of the elements who's attributes should be set.
table | The table item containing the positions of the elements where attribute should be set. |
field | The table item field where element positions are stored. |
/Resetpos
|
All element positions will be deleted after use. |
/All
|
All table entries will be used. This is the default. |
/Tagged
|
Only tagged entries will be used. |
/Value
|
The avalue arguments are attribute values. |
/Fieldid
|
The avalue arguments are table field names which contain attribute values. |
SET xmlfile SETATTRIBUTE tag aname avalue … [/Y] [/Recursive]
Set all the attributes of tag elements on the current level.
tag | The tag identifying the elements to modify. |
/Y
|
If the /Y option is used, the tag argument is used as a DOCTYPE class name, not an element tag. All derived classes are set too.
|
/Recursive
|
If specified, the command is carried out on the sub-tree as well. |
XML: SORT
SET xmlfile SORT [attrID0 dir0 attriIDN dirN] [/Delete]
Sort the children of the selected element according to the given attributes and directions and set the element's sort
attribute. Previous sort attributes are overwritten. Calling this function without parameters re-sorts using the existing attributes. Calling the function without parameters but with the /Delete
option removes the sort attributes. This function only supports attributes defined in the doctype. Note that if one of the attributes is unique (as defined in the doctype definition), only this attribute will be used to sort.
attrId | The name of an attribute defined in the doctype. |
dir | The direction in which the elements should be sorted. The following values are allowed: Ascending and Descending (and any shorter version thereof, e.g. Asc or Desc or a or d ) as well as 0 and 1
|
/Delete
|
If no parameters are passed, the existing sort attributes are deleted. |
The internal implementation works in the following way:
- Unique Attributes
- If one of the attributes passed to the
SORT
command is unique (as defined in the doctype), only this attribute is used for sorting. The elements are then sorted according to the direction and case is respected, if so defined in the doctype. All elements added to this level after sorting are added at the correct sorted position. Changing attributes of sorted elements also rearranges the sort order. If you have a large number of segments in anAFile
, sorting according to a unique attribute is highly recommended, since the performance of the dataset validation is very bad for unsorted unique attributes. If you set the parentsort
attribute by hand and want the sort to happen automatically, please set theunsorted
attribute to1
. Now the next time an attribute is changed, or an element is added, all elements will first be sorted. - Non-unique Attributes
- If the sort attributes are not unique, multiple attributes can be used. Elements added after sorting are not inserted at the correct position; instead, a further attribute
unsorted
is set in the parent element. Changing attributes after sorting does not affect the sort order – the parent attributeunsorted
is set. - Validation
- The
VALIDATE
command checks for sort attributes and sorts the elements before validation. When closing STx, the DataSet is validated, and therefore all elements with sort attributes are sorted.
Examples
$#xmlfile SORT ID Asc
The children of the selected element are sorted by their ID attribute in ascending order. The following command does the same by means of the SETATTRIBUTE command:
SET $#xmlfile SETATTRIBUTE sort 'ID Asc' unsorted '1'
When the selected element of $#xmlfile
is an AFile, all ASegs in this AFile will be sorted according to their ID. Sorting will happen automatically, either on modification/addition of an element or attribute to one of the ASegs, or on validation.
XML Element Data Manipulation
Note: You cannot store data in the data section of an element with children!
XML: GETDATA
SET xmlfile GETDATA varname
Copy contents of XML data section into variable varname.
SET xmlfile GETDATA /Table table /Read
Empty table and copy contents of the XML data section into the table item table. This command loads data stored in the format generated by the command SET $#xmlfile SETDATA /T $#table
.
SET xmlfile GETDATA /Table table [ firstField nFields ] /Numeric [/Vector]
Empty the table item table and copy the contents of the data section of the selected element into the numeric fields of the table. The GETDATA
command loads data stored in the format set by the command SET $#xmlfile SETDATA /T/N $#table $#firstField $#nFields
. Furthermore, it uses the attributes dim
and vector
set by the SETDATA
command to ascertain the format of the data section. If the option /Vector
is specified (see SETDATA
below), it overrides the corresponding vector
attribute if it exists.
XML: SETDATA
SET xmlfile SETDATA string [ /CData ]
string | The string to save in the element. |
Set the data of the selected element to string. An empty string can be used to remove data (leading to an empty element). If the string contains characters which are reserved in the XML specification (e.g. <, >, &), the option /CData
must be used, which will create a CData
section.
SET xmlfile SETDATA /Table table [ /CData ]
table | The table containing the data to be stored in the element. |
/Table
|
A mandatory option. |
Store the content of table in the data section of the selected element (note: this is different from ADDTABLE
, which adds one element per entry). The write format of the table is always used (see SET table FORMAT
). If table contains characters which are reserved in the XML specification, the option /CData
must be used.
SET xmlfile SETDATA /Table table [ firstField nfields ] /Numeric [ /Vector ]
firstField | The first field to extract data from. |
nFields | The number of consecutive fields to extract data from. |
/Numeric
|
A mandatory option. |
Store the contents of table in the data section of the selected element. The table must be an extended table and the selected fields must be numeric! The values are stored as decimal numbers. The data is stored row-by-row (if no additional option is supplied) or column-by-column (if option /Vector
is given). The attribute dim
is automatically added to the selected element with the values "nRows nColumns"
. If the option /Vector
is specified, the attribute vector
is added with the value "1"
.
XML Element Positions
Element positions are unique ID strings which can be used like pointers or references to an element. The position of an element is saved with the command "#posvar := POSITION $#file
" (see the command POSITION
).
XML: POSITION
SET xmlfile POSITION [ parameters … ] [ /Silent ]
All POSITION
commands support the /Silent
option.
SET xmlfile POSITION pos /Restore [ /Silent ]
Select the element at position pos and delete the position.
SET xmlfile POSITION pos /Goto [ /Silent ]
Select the element at position pos but do not delete the position.
SET xmlfile POSITION [pos|*] /Delete [/Children] [ /Silent ]
Delete the position identified by pos. If pos is empty or an asterisk, then all saved positions for the selected element are deleted. If the option /Children
is used, this position deletion is carried out recursively.
SET xmlfile POSITION pos1 [pos2] /Equal [ /Silent ]
Tests if the two positions pos1 and pos2 reference the same element (RC=0
for same element, RC=1
for different elements). If only one position (pos1) is passed, this position is compared with that of the selected element.
XML Load & Save
XML: LOAD
SET xmlfile LOAD [path]
Load the document from the last selected or specified path and select the root element (previous content/position information is lost). If a path is specified, data are loaded from path and it is stored for later use, otherwise the stored path is used. The current content and all position and state settings are cleared before loading.
The function sets RC to 0 on success.
XML: SAVE
SET xmlfile SAVE [path]
Store (i.e., save to disk) the document in the supplied path or, if none is supplied, in the last selected path. If path is specified, it is also stored for later use.
The following general navigation options can be supplied with any of the navigation, search and data processing command:
/In
step into the selected element: set the selected element to the parent element and its first child to the selected element; this option is applied after successful execution of the navigation or manipulation function/Out
step out of the parent: set the element containing the current parent to the new parent and the current parent to the selected element; this option is applied before the function is executed/First
,/Last
and/Next
set the position to the first or last element of the current section (/First
or/Last
) or continue navigation/search (/Next
); these options are applied before the respective function is executed (but after the/Out
option)./nodetype
selects the type of the node to be found; the types /Element, /Processinginstruction, /Comment and /Doctype are supported
XML: FIND
SET xmlfile FIND
The FIND
command searches an XML file for one, or more, occurences of a certain node. There are two variants of using the command:
- consecutively searching for the first (
SET xmlfile FIND /First
), and any further occurence (SET xmlfile FIND /Next
); or - searching for all occurrences in a single operation, returning them in an STx table (
SET xmlfile FIND tableitem…
)
Consecutive FIND
operations
SET xmlfile FIND *|tag [ cexpr [ loper …]] [/In|Out /First|Next] [/Element|Processinginstruction|Doctype] [/Y]
Search for a node of the selected type (/Element
which is the default, /Processinginstruction
, /Doctype
, see SET file GOTO
) with the tag * or tag on the level of the selected element. For nodes of type element the arguments cexpr (conditional expression for attribute values, see the table below and loper (logical operator) are formatted and processed similarly to the SET table
FIND
function (e.g. attributename:<=:1000
or attributename:=I:a*.0*
). Use the option /First
(default) to begin search at the first element in the section, and /Next
to start with the element following the selected element. If the node is found, it is selected, otherwise the selection remains unaffected. If the option /Y
is specified, then tag is treated as a DOCTYPE
class name, rather than an XML element tag (this means derived types are also recognised).
The shell variable RC
is set to the integer 7
if the command was syntactically correct, but no element was found. The shell variable RC
is set to the integer value 0
if an element corresponding to the search criteria was found.
Example
Find and delete the first element on the current level that has an ID
attribute with a value of 3
:
$#f find * 'ID:==:3' /First if '$rc' == 0 $#f deleteelement
Returning all results in a table
SET xmlfile FIND postable posfield tag [ cexpr [ loper cexpr …]…] [/Recursive /Y]
Like the above FIND
commands, except that the command does not return when it finds the first match, rather it saves the position of all matching elements in one field (posfield) of the specified table (postable). If the option /Recursive
is specified, the whole sub-tree is searched. If the option /Y
is specified, the tag string is treated as a DOCTYPE
class name rather than an element tag, and all derived classes are searched.
posTable | The extended table where to store element positions. |
posField | The extended table field in which to store element positions. |
For all other parameters, please see the consecutive variant of the FIND
command (above), and the table of cexpr
expressions (below).
Example
// find all elements with a specific numerical attribute value $#f find $#t $#tField $#elem '$#elemAttr:==:$#elemattrvalue' /Recursive
Find Conditions
format of cexpr | description | ||||||||||||||
attrname:cond
|
Check if a value is, or is not, assigned to an attribute. attrname is the name of the attribute (case sensitive!)
cond (=…is assigned, !…is not assigned) | ||||||||||||||
attrname:cond:value
|
Check the value of an attribute. attrname is the name of the attribute (case sensitive!)
| ||||||||||||||
attrname:cond:value
|
Match the value of an element's attribute
|
XML: GOTO
SET xmlfile GOTO [epath] [/First|Next|Last] [/In|Out] [/Element|Comment|Processinginstruction|Doctype] [/Reset]
Go to the first (/First
, last (/Last
) or next (/Next
) element. If epath is specified, go to the first (/First
, last (/Last
) or next (/Next
) element matching epath.
You can specify the type of node to navigate to with the options /Element
, /Comment
, /Processinginstruction
and /Doctype
, respectively. If only the node type option is used (without argument and other options), the first node of the respective type in the document is located.
The options /First
, /Next
and /Last
only work with epath if epath does not contain slashes, i.e. if it specifies an element tag without an actual path (e.g. "elemtag
"). For multi-level epaths like '*/elemtag
' or '/root/elemtag/elemtag
', the search finds the first element every time, and neither of /First
, /Next
and /Last
should be supplied.
epath | The path of the element to go to. The normal format of epath is "elemtag ". If you want to go to an element on a deeper level, the format is '*/elemtag '. The format of epath is absolute if it starts with the forward slash (e.g. '/rootelem/firstelem '). To ensure that epath is correctly interpreted, always enclose it in single quotation marks. XML is case sensitive, so epath must match exactly (wildcards are not supported). If no options are given, the current position is reset to the first child element of the root element.
|
/First , /Next or /Last
|
Determines whether to navigate to the first, last or next element. The default is /Next .
|
/E |
Navigate to a data element node (e.g. <elemtag> )
|
/C |
Navigate to an XML comment (e.g. <!-- comment --> ). The argument epath is ignored.
|
/P |
Navigate to an XML processing instruction (e.g. <?pinst …?> ). The argument epath is used as the tag name of the processing instruction node.
|
/Doctype |
Navigate to a document type (e.g. <!DOCTYPE typename …> ). The argument epath is used for the name of the document type. The default is /Element .
|
/Reset
|
Reset the element selection. This means that no element is selected and a GOTO command with the option /Next will navigate to the first element. |
/In
|
step into the selected element: set the selected element to the parent element and its first child to the selected element; this option is applied after successful execution of the navigation or manipulation function |
/Out
|
step out of the parent: set the element containing the current parent to the new parent and the current parent to the selected element; this option is applied before the function is executed |
Note that you can get yourself into difficulties if you use multiple options, e.g /i /f
. Although you may feel inclined to think you are going to navigate in and go to the first element there, you will actually go to the first element and then navigate in.
You can use the file item attribute !XCHILDREN
to determine if an element has children or not.
RC is set to 0 if the element is found and a value greater than 0 if not.
Example
// go to the root element <STxColorPalette> $#xmlfile goto '/STxColorPalette'