Home > Language Reference > XML Functions > EnumXMLChildren

EnumXMLChildren

The EnumXMLChildren function enumerates the child node descriptors for the specified XML node.

Syntax

ret = EnumXMLChildren(<XML_filename>, <XML_path>, <tab_child_node>)

Parameters

<XML_filename>. string, name of the XML file.

<XML_path>. string, XML path (case insensitive). See Remarks below to know how is built such a path.

<tab_child_node>, array of strings. It contains the attribute names under the XML path. The array must be declared at the beginning of the script using the Dim function. Array index starts at 0.

<tab_attribute_value>, array of strings. It contains the child nodes under the specified XML path. The array must be declared at the beginning of the script using the Dim function. Array index starts at 0.

Return value

ret, optional integer return value. If the function succeeds, the return value is the number of returned nodes. If the function fails, the return value is a negative value, an XML Functions Error Code  preceeded by the minus sign.

Remarks

A XML path is a list of node descriptors separated by the \ character.

The XML path can include tagnames such as:
tagname[attributename1='value']
The tagnames are strings without double quotes, they cannot contain spaces or reserved characters. 

The XML path can include attribute names. They 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'], for example :
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']"

See also

AppendXMLNode
EnumXMLAttributes
GetXMLAttribute
SetXMLAttribute

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>

'Script displaying the attribute value of the children below bookstore\book[category='CHILDREN']
dim children$(100)

file$ = "c:\wttest\sample.xml"

'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:\wttest\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