This section provides guidance for constructing the XPath for different elements within a response, using the following XML as an example. The table below the XML lists several examples of correct XPath syntax and explains which node(s) these XPaths map to. In addition, the table indicates the appropriate variable mapping to use for each XPath. 

<?xml version="1.0" encoding="UTF-8"?>

<bookstore>

<book>
<title lang="fr">Harry Potter</title>
<price>29.99</price>
</book>

<book>
<title lang="en">Learning XML</title>
<price>39.95</price>
</book>

</bookstore>
XPathMaps ToRecommended Variable Type Mapping/Notes
/bookstore
The entire XML response. This syntax would be used only if the response contained a single element, e.g., a string. In that case, simple type mapping is used.
/bookstore/book
All elements inside the <bookstore> tag. In our example, the title and price of both books would be returned. Collection of book objects.
If mapping to a collection is not done, the title and price of the first book are returned.
/bookstore/book[2]
The title and price of the second book. Single book object.
/bookstore/book/title
The titles of all books. Collection of strings.
If mapping to a collection is not done, the title of the first book is returned.
/bookstore/book[1]/title
The title of the first book. Simple text variable.
/bookstore/book/title[@lang='en']
All titles that have an attribute lang with a value of en. Collection of strings.
If mapping to a collection is not done, the first title that matches the XPath is returned (in our example, this would be the title of the second book).

 

Revision:

Comments