Get XML Attribute

Retrieves one or more attribute values from the specified XML element.

 

Input Arguments

 

0

Integer

XML File Handle

The handle to the XML file as returned from the

Open XML File command.

1

String

XPath

The XPath to the node to read from.

 

Return Arguments

Return arguments are user-defined.

 

Returned Status

 

SUCCESS

The attributes were retrieved successfully.

FAILURE

One or more attributes or a valid node was not found.

 

Remarks

You can retrieve one or more attribute values from a specific node by specifying the XPath to that node. (XPath is widely-adopted standardized query language for selecting nodes from an XML document).

Once the node of interest is specified by the XPath, the actual attribute values are retrieved by adding return argu- ments in the command. The Type of the argument specifies the data type the value will be returned as, whereas the Descriptor for the argument must match the XML attribute name perfectly. For example, for an XML file excerpt that looks like this,

<ROOT>

<BOOK TITLE=”Mastering Metrology” AUTHOR=”S. M. Arr” PAGES=”1023”>

<BOOKMARK PAGE=”144” />

</BOOK>

<BOOK TITLE=”A Christmas Carol” AUTHOR=”Charles Dickens” PAGES=”95”>

<BOOKMARK PAGE=”3” />

<BOOKMARK PAGE=”15” />

</BOOK>

</ROOT>

you can retrieve the author and length of A Christmas Carol by specifying the following XPath string:

/ROOT/BOOK[@TITLE=”A Christmas Carol”]

and adding two return arguments: one of type String with the descriptor AUTHOR, and the other of type Integer with the descriptor PAGES.

In layman’s terms the command will search through the xml file as specified in the XPath. It will start with <Root> then look for <Book> and then when it finds a matching entry it will look for where TITLE=”A Christmas Carol” and

 

then all the descriptors under /Root/Book become available (TITLE, AUTHOR, PAGES). To go one level deeper you could specify:

/ROOT/BOOK[@TITLE=”A Christmas Carol”]/BOOKMARK[2]

and then return a descriptor PAGE. The command will find the first bookmark in the section and return “15”. There- for, by using a counter you can index through a list even if a specific descriptor is not know.

 

 

**A nice trick is to install Notepad ++ with the XML plug-in or similar resource. This allows you to open an XML page, select an attribute and have it generate the path for you which can then be pasted into the MP command.