Xpath Query
  • 17 Feb 2020
  • 1 Minute to read
  • Dark
    Light
  This documentation version is deprecated, please click here for the latest version.

Xpath Query

  • Dark
    Light

Article summary

Overview

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.

Example

Begin in the Designer Folder and select Create Flow

2019-06-25_1536.png

Next, name the Flow and select CREATE to proceed to the Flow Designer.

2019-06-25_1537.png

In the Flow Designer add Create Data step from the Favorite Steps category.

2019-06-25_1538.png

Then, in the resulting window select Show Editor under Data Definitions.

2019-06-25_1539.png

Name the data to create and define as a String Type. Select CLOSE to continue.

2019-06-25_1540.png

Next, use Text Merge.Plain mapping type for the data definition Input and select Show Editor.

2019-06-25_1541.png

In theText Merge Editor paste the XML and select OK to save and close Text Merge Editor.

2019-06-25_1600.png

Then, add the XPath Query step from the All Steps [Catalog] > Data > XML category.

2019-06-25_1601.png

Select XPath Query step on the workspace to configure it. First check Get Xpath from Input checkbox.

2019-06-25_1603.png

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[1]. This query selects the first book element that is the child of the bookstore element.

2019-06-25_1604.png

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.

2019-06-25_1605.png

And, the outcome from the XPath Query step is the first book in the bookstore.

2019-06-25_1631.png

Query Examples for this exampleWhat 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]/titleSelects 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

Was this article helpful?

What's Next