- 17 Feb 2020
- 1 Minute to read
- Updated on 17 Feb 2020
- 1 Minute to read
XPath uses path expressions to select nodes or node-sets in an XML document. The node is selected by following a path or steps. This tutorial demonstrates how to use the XPath Query step in Decisions to be able to query XML documents.
Begin in the Designer Folder and select Create Flow
Next, name the Flow and select CREATE to proceed to the Flow Designer.
In the Flow Designer add Create Data step from the Favorite Steps category.
Then, in the resulting window select Show Editor under Data Definitions.
Name the data to create and define as a String Type. Select CLOSE to continue.
Next, use Text Merge.Plain mapping type for the data definition Input and select Show Editor.
In theText Merge Editor paste the XML and select OK to save and close Text Merge Editor.
Then, add the XPath Query step from the All Steps [Catalog] > Data > XML category.
Select XPath Query step on the workspace to configure it. First check Get Xpath from Input checkbox.
Then, select the Path of the Defined XML Data under Input > To Query to this step.
In the XPath input to this step define a Constant query: /bookstore/book. This query selects the first book element that is the child of the bookstore element.
Then connect the Done outcome path from the XPath Query step to the End step in the Flow. This completes the Flow. Select Debug on the top action panel of the Flow Designer to test the Flow.
And, the outcome from the XPath Query step is the first book in the bookstore.
|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|