AppendXMLNode
File management function.
The AppendXMLNode function adds a node in the specified XML file. Not available in WinTask Lite.
Syntax
AppendXMLNode(<filename>,<XML_path>,<tagname>)
or
ret=AppendXMLNode(<filename>,<XML_path>,<tagname>)
Parameters
<filename>, string, name of the XML file where to add the node.
<XML_path>, string, list of node descriptors separated by the \ character for adding the node after this list. The string is not case-sensitive. The structure of such a path is:
tagname[attributename1='value']
The tagnames are strings without double quotes, they cannot contain spaces or reserved characters. It can be an empty string to create the root node.
The attribute names are strings without double quotes, OR it can be the reserved keyword <text> or the reserved keyword <index>. <text> is used to specify the node inner text, <index> is used to specify the node index (first one starts at 1) when more nodes with the same tag and attributes exist within the same parent. Several attributes can be listed with the syntax tagname[attributename1='value1', attributename2='value2']
Examples:
If the XML file contains:
<bookstore>
<book genre="autobiography" publicationdate="1981" ISBN="1-861003-11-0">
the <XML_path> can be "bookstore\book[genre='autobiography']" or "bookstore\book[publicationdate='1981']" or "bookstore\book[publicationdate='1981',genre='autobiography']"<tagname>, string, value of the tag to be added.
Return value
Ret, numeric return code. When the node is successfully added to the XML file, the function returns 0, otherwise use this return code for Error Handling. The error codes are :
20
The XML file could not be saved
27
The XML file could not be opened
90
Internal error (COM error when invoking XML COM)
99
Invalid parameters
110
Invalid XML path
See also
Example
This code will generate the XML file as below:
file$ = "c:\program files\wintask\scripts\test.xml"
create(file$)
appendxmlnode(file$, "", "root")
appendxmlnode(file$, "root", "book")
appendxmlnode(file$, "root", "book")
appendxmlnode(file$, "root\book", "Mark_Twain")
appendxmlnode(file$, "root\book", "Mark_Twain")
appendxmlnode(file$, "root\book[<index>=2]", "Portugalia")
setxmlattribute(file$, "root\book\Mark_Twain", "<text>", "Misc description")
setxmlattribute(file$, "root\book\Mark_Twain[<index>=2]", "year", "1987")
setxmlattribute(file$, "root\book\Mark_Twain[year='1987']", "<text>", "Another misc description")Resulting XML file:
<root>
<book>
<Mark_Twain>Misc description</Mark_Twain>
<Mark_Twain year="1987">Another misc description</Mark_Twain>
</book>
<book>
<Portugalia />
</book>
</root>