Home > Language Reference > XML Functions > EnumXMLAttributes

EnumXMLAttributes

The EnumXMLAttributes function retrieves the attribute names and attribute values for the specified XML node.

Syntax

ret = EnumXMLAttributes(<XML_filename>, <XML_path>, <tab_attribute_name>, <tab_attribute_value>)

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_attribute_name>, 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 attribute values for the corresponding attribute names. 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 attributes. If the function fails, the return value is a negative value, an XML Function 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
EnumXMLChildren
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>

'Retrieve the number of attributes under bookstore\book\[<index>=2] XML node
dim children$(100)
dim name$(100)
dim value$(100)

file$ = "c:\wttest\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))