Home > Language Reference > XML Functions > GetXMLAttribute


The GetXMLAttribute function returns the attribute value for the specified attribute name.


ret = GetXMLAttribute(<XML_filename>,<XML_path>,<attribute_name>,<returned_value>)


<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.

<attribute_name>, string, attribute name. It can be too "text" (surrounded by the ") to retrieve the content of the text between the starting tag and the ending tag of the tag specified in <xml_path>.

<returned_value>, string, variable only. It contains the attribute value for <attribute_name>.

Return value

ret, optional integer return value. If the function succeeds, the return value is zero. If the function fails, the return value is a nonzero value (see XML Functions Error Codes).


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

The XML path can include tagnames such as:
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:
  <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



'This script generates a XML file and GetXMLAttribute is used to retrieve the content of 2 attribute names just created.
file$ = "c:\wttest\test.xml"
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")
getxmlattribute(file$, "root\book\Mark_Twain[<index>=2]", "year", val$)
msgbox(val$) 'val$ contains 1987
getxmlattribute(file$, "root\book\Mark_Twain[year='1987']", "<text>", val$)
msgbox(val$) 'val$ contains Another misc description

With this XML file:
<book category="COOKING">
<title lang="en">Everyday Italian</title>
<author>Giada De Laurentiis</author>
<book category="CHILDREN">
<title lang="en">Harry Potter</title>
<author>J K. Rowling</author>
<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>
<book category="WEB">
<title lang="en">Learning XML</title>
<author>Erik T. Ray</author>

'This script returns the text titles for the books in category WEB:
dim children$(100)
file$ = "c:\wttest\sample.xml"
ret = enumxmlchildren(file$, "bookstore", children$())
while i < ret
  getxmlattribute(file$, children$(i), "category", val$)
  if val$ = "WEB" then
  getxmlattribute(file$, children$(i)+"\title[lang='en']", "<text>", val$)
  i = i+1