Skip to content
Documentation
Updated 3 minutes to read
Markdown

The xPath Formula function returns the values in XML content that match an XPath 1.0 expression.

Read the order id from an Order Entry XML event with xPath, animated walkthrough (7.12)
Animated walkthrough: xPath('OrderEntry/OrderHeader/OrderId', body) on the Order Entry XML of the Order-to-Cash demo returns ORD-10005. The XML has a default namespace, and the path matches without a prefix.

xPath('expression', content)
Parameter Required Description
'expression' Yes An XPath 1.0 expression in single quotes, such as '/Orders/Id'. A literal ' inside it is written ''.
content Yes The XML text: body, context, or the result of another function, such as base64decode (see Formula language rules).

The text value of every matching element or attribute, one value each; duplicates are collapsed. When nothing matches, nothing is returned.

Element names match without namespace prefixes or declarations: Orders/Order/Id matches <ns0:Orders xmlns:ns0="…"> (see Formula language rules).

<Id>3</Id>
xPath('/Id', body)
3

Formula xPath expression returning 3 from an XML message body in the Test Expression tab (7.12)
/Id selects the root element Id and returns its text.

Example 2: Read all order IDs from base64-encoded XML

Section titled “Example 2: Read all order IDs from base64-encoded XML”
PE9yZGVycz4KICA8SWQ+MzwvSWQ+CiAgPElkPjY8L0lkPgo8L09yZGVycz4=

The body decodes to:

<Orders>
<Id>3</Id>
<Id>6</Id>
</Orders>
xPath('/Orders/Id', base64decode(body))
3
6

Formula xPath over base64decode of the body returning the order IDs 3 and 6 in the Test Expression tab (7.12)
base64decode turns the body into XML first; xPath then returns both Id values.

Example 3: Read XML stored in a context property

Section titled “Example 3: Read XML stored in a context property”
Key Value
id <Id>3</Id>
xpath('/Id',context('id'))
3

Test Expression tab: xpath('/Id',context('id')) reads the XML in the id context property and returns 3 (7.12)
The XML in the id context property is queried like a message body.

Example 4: Pick an attribute by its content and clean it up

Section titled “Example 4: Pick an attribute by its content and clean it up”
<Root>
<Data Data="SENDERID:13"/>
<Data Data="VATNO:SE19840410-1337"/>
<Data Data="RECEIVERID:37"/>
</Root>
replace('VATNO:', '', xPath('/Root/Data[contains(@Data, ''VATNO'')]/@Data', body))
SE19840410-1337

The predicate keeps the Data element whose attribute contains VATNO; the doubled ''VATNO'' is the escaped single quote inside the quoted XPath, so XPath receives 'VATNO'. replace then removes the VATNO: prefix.

Formula replace around xPath returning the VAT number SE19840410-1337 from a Data attribute in the Test Expression tab (7.12)
Of the three Data attributes, only the VATNO one is selected, and replace strips its prefix to leave the bare VAT number.

  • Expressions that look back, such as .. or parent::, return no values, and the test bench shows the warning xpath is not supported!; see Allowed XPath expressions for what the forward-only reader supports.
  • A predicate on a child element, such as Orders/Order[Id=2]/City, isn't supported either: the test bench shows Can't get the child value. An attribute test such as [contains(@Data, ''VATNO'')] works (Example 4).
  • A leading //, such as //Id, returns nothing. Write the path from the root.
  • xPath is the better choice for large XML; use xPath2 only when you need what the forward-only reader refuses.
  • For one XPath on the body, the XPath plugin does the same without a formula; for XML in a context value, use the XPath on Message Context plugin. See Choose a plugin.

...

Version:
Release date: N/A
Loading...

Explore Nodinite for 30 days – completely free

  • Find out why this is the leading O&M software
  • Prove your business case
  • Test the self-service for the business side

Loading...

See how Nodinite resolves your technical issues, in a LIVE Demo!

Once you submit this request:

  • We will give you a short call to understand the issues you want to tackle.
  • Understand solutions you have tried and why were you not happy with them.
  • Book a convenient slot for a LIVE demo!

Loading...