Formula - xpath2
Section titled “ Formula - xpath2”The xPath2 Formula function returns the values in XML content that match an XPath expression evaluated over the whole document: full XPath 1.0, with every axis and predicates on child elements. Despite its name, it isn't XPath 2.0.

Animated walkthrough: on a logged Contoso HR message (the input of Example 1 below), xPath2('/Root/Ids/Id[Name=''EmployeeID'']/Value', body) returns 1337 in the Test Expression tab. The same expression with xPath is refused: Can't get the child value.
Syntax
Section titled “ Syntax”xPath2('expression', content)Parameters
Section titled “Parameters”| Parameter | Required | Description |
|---|---|---|
'expression' |
Yes | An XPath 1.0 expression in single quotes, with the document's namespace prefixes (see Namespaces). 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
Section titled “Returns”The inner XML of every matching node, one value each: the text for an element without child elements, and markup (<Name>EmployeeID</Name>…) for an element with child elements. Duplicates are collapsed: xPath2('/a/b', body) on <a><b>7</b><b>7</b></a> returns one 7. When nothing matches, nothing is returned.
Namespaces
Section titled “ Namespaces”Unlike xPath, xPath2 needs the namespace prefixes the document uses:
| XML | Expression | Result |
|---|---|---|
<ns0:Orders xmlns:ns0="…"><Order><Id>101</Id></Order></ns0:Orders> |
xPath2('/ns0:Orders/Order/Id', body) |
101 |
| The same XML | xPath2('/Orders/Order/Id', body) |
Nothing |
<OrderEntry xmlns="…"><OrderHeader><OrderId>ORD-10005</OrderId>… |
xPath2('//*[local-name()=''OrderId'']', body) |
ORD-10005 |
With a default namespace (xmlns="…"), unprefixed names never match; use local-name() as in the last row.
Examples
Section titled “ Examples”Example 1: Read a value by the name next to it
Section titled “Example 1: Read a value by the name next to it”<Root> <Ids> <Id> <Name>EmployeeID</Name> <Value>1337</Value> </Id> <Id> <Name>Company</Name> <Value>ACME</Value> </Id> </Ids></Root>Formula
Section titled “Formula”xPath2('/Root/Ids/Id[Name=''EmployeeID'']/Value', body)Result
Section titled “Result”1337
The predicate [Name='EmployeeID'] tests a child element of Id, then the expression returns the sibling Value.
- The predicate in the example tests a child element, which the forward-only reader of xPath doesn't support:
xPathrefuses it with Can't get the child value. The forward-only reader supports predicates on attributes of the current element only. xPath2loads the whole document in memory instead of reading it forward, so expect it to use more memory thanxPathon large messages.