Formula - XPath
The xPath Formula function returns the values in XML content that match an XPath 1.0 expression.
Note
xPathreads XML with a forward-only reader and supports the XPath 1.0 subset listed in Allowed XPath expressions. For XPath 2.0 syntax, use xPath2.
Syntax
xPath('expression', content)
Parameters
| 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). |
Returns
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).
Examples
Example 1: Read an element from the body
Input
<Id>3</Id>
Formula
xPath('/Id', body)
Result
3

/Id selects the root element Id and returns its text.
Example 2: Read all order IDs from base64-encoded XML
Input
PE9yZGVycz4KICA8SWQ+MzwvSWQ+CiAgPElkPjY8L0lkPgo8L09yZGVycz4=
The body decodes to:
<Orders>
<Id>3</Id>
<Id>6</Id>
</Orders>
Formula
xPath('/Orders/Id', base64decode(body))
Result
3
6

base64decode turns the body into XML first; xPath then returns both Id values.
Example 3: Read XML stored in a context property
Input
| Key | Value |
|---|---|
| id | <Id>3</Id> |
Formula
xpath('/Id',context('id'))
Result
3

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
Input
<Root>
<Data Data="SENDERID:13"/>
<Data Data="VATNO:SE19840410-1337"/>
<Data Data="RECEIVERID:37"/>
</Root>
Formula
replace('VATNO:', '', xPath('/Root/Data[contains(@Data, ''VATNO'')]/@Data', body))
Result
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.

Of the three Data attributes, only the VATNO one is selected, and replace strips its prefix to leave the bare VAT number.
Notes
- Expressions that look back, such as
..orparent::, return no values; see Allowed XPath expressions for what the forward-only reader supports. xPathis the better choice for large XML; use xPath2 only when you need XPath 2.0.- 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.