Skip to content
Documentation
Updated 3 minutes to read
Markdown

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.

Read an employee id by the name next to it with xPath2, where xPath refuses, animated walkthrough (7.12)
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.

xPath2('expression', content)
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).

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.

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.

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>
xPath2('/Root/Ids/Id[Name=''EmployeeID'']/Value', body)
1337

Formula xPath2 expression with a child-element predicate returning 1337 in the Test Expression tab
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: xPath refuses it with Can't get the child value. The forward-only reader supports predicates on attributes of the current element only.
  • xPath2 loads the whole document in memory instead of reading it forward, so expect it to use more memory than xPath on large messages.

...

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...