Configuring the XPath for SOAP IP Responses
Here's a brief guide to constructing the XPath for different elements within a response, using the following XML as an example:
<?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>
This table lists some examples of correct XPath syntax, their mapped node(s), and valid Variable Types.
XPath | Maps To | Recommended 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). |