EnumXMLChildren
File management function.
The EnumXMLChildren function enumerates the child node descriptors for the specified XML node. Not available in WinTask Lite.
Syntax
EnumXMLChildren(<filename>,<XML_path>,<child_node_array>)
or
ret=EnumXMLChildren(<filename>,<XML_path>,<child_node_array>)
Parameters
<filename>, string, name of the XML file where to add/modify the attribute.
<XML_path>, string, list of node descriptors separated by the \ character to go where the attribute is. 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.
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']"<child_node_array>, array of strings. The content of the cells beginning with element 0 returns each child node under the specified XML node.
Return value
Ret, numeric return code. When the attribute value is successfully inserted in the XML file, the function returns 0, otherwise use this return code for Error Handling. The error codes are :
27
The XML file could not be opened
90
Internal error (COM error when invoking XML COM)
99
Invalid parameters
110
Invalid XML path
112
Index too big
See also
Example
XML file:
<bookstore>
<book category="COOKING">
<title lang="en">Everyday Italian</title>
<author>Giada De Laurentiis</author>
<year>2005</year>
<price>30.00</price>
</book>
<book category="CHILDREN">
<title lang="en">Harry Potter</title>
<author>J K. Rowling</author>
<year>2005</year>
<price>29.99</price>
</book>
<book category="WEB">
<title lang="en">XQuery Kick Start</title>
<author>James McGovern</author>
<author>Per Bothner</author>
<author>Kurt Cagle</author>
<author>James Linn</author>
<author>Vaidyanathan Nagarajan</author>
<year>2003</year>
<price>49.99</price>
</book>
<book category="WEB">
<title lang="en">Learning XML</title>
<author>Erik T. Ray</author>
<year>2003</year>
<price>39.95</price>
</book>
</bookstore>
dim children$(100)
dim name$(100)
dim value$(100)
file$ = "c:\program files\wintask\scripts\sample.xml"
ret = EnumXMLAttributes(file$, "bookstore\book[<index>=2]", name$(), value$())
'ret returns the number of attributes under bookstore\book\[<index>=2] XML node
msgbox(ret)
' Displays the first attribute name and its value
msgbox(name$(0) + "=" + value$(0))
'children$(0) returns the first child node of bookstore\book[category='CHILDREN']
ret = enumxmlchildren(file$, "bookstore\book[category='children']", children$())
'the array children$() can then be used to loop on each child node and retrieve their attribute values
i=0
while i < ret
getxmlattribute(file$, children$(i), "<text>", val$)
msgbox(val$)
i = i+1
wend
On the same file, the script below returns the text titles for the books in category WEB:
dim children$(100)
file$ = "c:\program files\wintask\scripts\sample.xml"
ret = enumxmlchildren(file$, "bookstore", children$())
i=0
while i < ret
getxmlattribute(file$, children$(i), "category", val$)
if val$ = "WEB" then
getxmlattribute(file$, children$(i)+"\title[lang='en']", "<text>", val$)
msgbox(val$)
endif
i = i+1
wend