- 2 minutes to read
Formula - xpath2
The xPath2 Formula function returns the values in XML content that match an XPath 2.0 expression.
Note
Use xPath when its forward-only XPath 1.0 subset is enough (see Allowed XPath expressions); it is the lighter choice for large XML. Use
xPath2when the expression needs more, such as a predicate on a child element.
Syntax
xPath2('expression', content)
Parameters
| Parameter | Required | Description |
|---|---|---|
'expression' |
Yes | An XPath 2.0 expression in single quotes. A literal ' inside it is written '', as in [Name=''EmployeeID'']. |
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 node, one value each; duplicates are collapsed. When nothing matches, nothing is returned.
Examples
Example 1: Read a value by the name next to it
Input
<Root>
<Ids>
<Id>
<Name>EmployeeID</Name>
<Value>1337</Value>
</Id>
<Id>
<Name>Company</Name>
<Value>ACME</Value>
</Id>
</Ids>
</Root>
Formula
xPath2('/Root/Ids/Id[Name=''EmployeeID'']/Value', body)
Result
1337

The predicate [Name='EmployeeID'] tests a child element of Id, then the expression returns the sibling Value. The screenshot writes xpath2; function names are case-insensitive.
Notes
- The predicate in the example is also valid XPath 1.0 syntax, but it tests a child element, which the forward-only reader of xPath doesn't support; it supports predicates on attributes of the current element only.
xPath2doesn't use the forward-only reader, so expect it to use more resources thanxPathon large messages.