@XMLNODES[["filename"],path] : Return the number of nodes (children) for the specified path in an XML file. The arguments are:

 

filename - name of XML file

path - one or more element accessors separated by a /.

 

If you don't specify a filename (which *must* be in double quotes), @XMLNODES will use the XML file previously opened by @XMLOPEN.

 

Example:

 

Bookstore.xml :

 

<?xml version="1.0" encoding="ISO-8859-1"?>

<bookstore>

<book>

   <title lang="jap">Harry Potter</title>

   <price>29.99</price>

</book>

<book>

   <title lang="eng">Learning XML</title>

   <price>39.95</price>

</book>

<book>

   <title lang="ger">Day Watch</title>

   <price>14.99</price>

</book>

<book>

   <title lang="eng">Winston Churchill: An Autobiography</title>

   <price>49.99</price>

</book>

</bookstore>

 

Bookstore.btm:

 

@ECHO OFF

SET a=%@XMLOPEN[bookstore.xml]

SET b=%@XMLNODES[/bookstore]

ECHO Total Nodes = %b

DO i = 1 to %b

       SET Title= %@XMLXPATH[/bookstore/book[%i]/title]

       SET Price= %@XMLXPATH[/bookstore/book[%i]/price]

       ECHO %Title ` costs only ` %Price

ENDDO

SET c=%@XMLCLOSE[]

 

Running bookstore.btm outputs:

 

Total Nodes = 4

Harry Potter  costs only   29.99

Learning XML  costs only   39.95

Day Watch  costs only   14.99

Winston Churchill: An Autobiography  costs only   49.99

 

XML Errors:

 

101 Invalid attribute index

102 No attributes available

103 Invalid namespace index

104 No namespaces available

105 Invalid element index

106 No elements available

107 Attribute does not exist

201 Unbalanced element tag

202 Unknown element prefix (can't find namespace)

203 Unknown attribute prefix (can't find namespace)

204 Invalid XML markup

205 Invalid end state for parser

206 Document contains unbalanced elements

207 Invalid XPath

208 No such child

209 Top element does not match start of path

210 DOM tree unavailable

302 Can't open file

401 Invalid XML would be generated

402 An invalid XML name has been specified