XPATH task to read elements/attributes

Using XPATH to Read Elements/Attributes in Business Processes

XPath is used to navigate through elements and attributes in an XML document. There might be times we need to read/interroagate the XML data without a ruleset. XPATH functionailty gives us the ability to perform this process.

In the example below we will extract the attribute:lang value from the <title> element.

XML Example

<?xml version="1.0" encoding="UTF-8"?>
<bookstore>
<book>
  <title lang="en">Harry Potter</title>
  <price>29.99</price>
</book>
</bookstore>

Business Process Set-up

Below we set-up 3 tasks to read the XML data and capture the attribute:lang value from the <title> element

XmlXpathQuery Task

In the first task we are going to read the XML data from the Storage Node via XmlXpathQuery We will use the XPATH of /Book/title[@en](string literal) to read the example XML data. Once the data is captured, we will place the data into xmlArry (Array).

Cleo Clarify 3 XML XPATH Query Attribute Business Process Task

GetArrayElement Task

Once the data is in the array, we will retrieve the data in the first position of the array via GetArrayElement Task. In this case, it will be position 0 (zero). The result will be placed into xmlResule (object)

Cleo Clarify 3 XML XPATH Get Element Array Business Process Task

ConvertToString Task

After the data is in an Object variable, we will use ConvertToString Task, to place the data into a string variable.

Cleo Clarify 3 XML XPATH Convert to String Business Process Task




By: on