Xpath Query
- 10 Feb 2021
- 2 Minutes to read
- Print
- DarkLight
This documentation version is deprecated, please click here for the latest version.
Xpath Query
- Updated on 10 Feb 2021
- 2 Minutes to read
- Print
- DarkLight
Article summary
Did you find this summary helpful?
Thank you for your feedback
Overview
XPath uses path expressions to select nodes or node-sets within an XML document. The node is selected by following a path or a set of steps.
The following tutorial demonstrates how to use the XPath Query step in Decisions as means to query XML documents.
Query Examples
The following chart displays a list of the Query elements used in the document's examples, with an explanation of each one.
Query Examples for this example | What they do |
---|---|
/bookstore/book[last()] | Selects the last book element that is the child of the bookstore element |
/bookstore/book[last()-1] | Selects the last but one book element that is the child of the bookstore element |
/bookstore/book[position()<3] | Selects the first two book elements that are children of the bookstore element |
//title[@lang] | Selects all the title elements that have an attribute named lang |
//title[@lang='en'] | Selects all the title elements that have a "lang" attribute with a value of "en" |
/bookstore/book[price>35.00] | Selects all the book elements of the bookstore element that have a price element with a value greater than 35.00 |
/bookstore/book[price>35.00]/title | Selects all the title elements of the book elements of the bookstore element that have a price element with a value greater than 35.00 |
/bookstore/ | Selects all the child element nodes of the bookstore element |
// | Selects all elements in the document |
//title[@*] | Selects all title elements which have at least one attribute of any kind |
//book/title | //book/price |
//title | //price |
/bookstore/book/title | //price |
Example
- Navigate to a Designer Project and select the CREATE FLOW button from the top Action bar.
- Select Flow, provide a Name, and click CREATE.
- Add a Create Data step from the FAVORITE STEPS category of the Toolbox tab.
- Navigate to the Create Data step's Properties tab.
- Under DATA > Data To Create, click SHOW EDITOR.
- Name the DataDefinition "XML", and select String [Text] from the Type dropdown.
- CLOSE out of the Data Definitions window.
- From the Properties tab of the Create Data step, under INPUTS, change the mapping for XML to Merge Plain Text, then click SHOW EDITOR.
- Copy and paste the following XML into the Merge Text Editor, then click SAVE.
<?xml version="1.0"?> <bookstore> <book> <title lang="en">Harry Potter</title> <price>29.99</price> </book> <book> <title lang="ru">Russian Book</title> <price>10.95</price> </book> <book> <title>Unknown</title> <price>55.95</price> </book> </bookstore>
- Attach an XPath Query step from the DATA > XML category in the Toolbox tab, to the Done path of the Create Data step.
- Navigate to the XPath Query step's Properties tab. Then, under QUERY, check Get XPAth from Input.
- Under INPUTS, map XML to To Query; then, Constant map /bookstore/book[1] to XPath.This Query selects the first "book" element that is the Child of the "bookstore" element.
Connect the Done path from the XPath Query step to the End step; then, Save the Flow.
If desired, the Flow may be closed by click X.
Debug
- From the Flow Designer, select the Debug link from the top Action bar.
- Click the START DEBUGGING button.
- View the Output Data for the XPath Querystep.The XPath Query Output will display Query the first "book" value in the "bookstore."
Was this article helpful?