- 4 minutes to read

Formula - xpath2

Easily extract values from XML messages using the Nodinite xpath2 Formula plugin. This page shows how to use XPath 2.0 expressions to retrieve data from message Content, Context, or the output of other formulas.

🎯 Designed for business users and integrators β€” no developer required; you can even use AI to craft expressions.

  • βœ… Extract single or multiple values from XML with advanced XPath 2.0 support from any Payload or Context in any Log Event
  • βœ… XPath 2.0 for complex queries and advanced data selection
  • βœ… Transform and surface meaningful data in Nodinite Log Views, search filters, and self-service diagnostics
  • βœ… Combine with other Formula functions for powerful, layered expressions

Info

Support for XPath 2.0 and more complex XPath queries. For less resource-intensive and limited XPath support, please review the xpath user guide.


What does the xpath2 Formula do?

The xpath2('Expression', Content) Formula function extracts values from XML structures using advanced XPath 2.0 syntax. You can use this function on message bodies, context values, or results from other formulas.


How it works: Input ➜ xpath2 ➜ Result

graph LR A["Input: XML document"] --> B["xpath2('Expression', Content)"] B --> C["Result: Extracted values"]

Flow: The XML content is queried using an XPath 2.0 expression to extract matching values.


Example

Below is a practical example showing how to extract a value from XML using an XPath 2.0 predicate expression.

Input

<Root>
  <Ids>
    <Id>
      <Name>EmployeeID</Name>
      <Value>1337</Value>
    </Id>
    <Id>
      <Name>Company</Name>
      <Value>ACME</Value>
    </Id>
  </Ids>
</Root>

Formula Expression

xpath2('/Root/Ids/Id[Name=''EmployeeID'']/Value', body())

Result

1337

Example

Example: Extracting a value from XML body using xpath2


Features

The xpath2 Formula function is highly flexible and can be nested with other formula functions. For instance, combine it with base64decode, concat, or replace to manipulate the XML content before or after extraction.

  • Extract single or multiple unique values from any XML content using XPath 2.0
  • Use any XPath 2.0 expression as defined by W3C
  • Works with message body, Context, or results from other Formula functions
  • Ensures data integrity across integrated systems

Warning

The xpath2 plugin loads the entire message into RAM and uses more CPU and memory than the simpler xpath function. Only use this function on small messages and when you need advanced XPath 2.0 features.


How to use

The xpath2 formula extracts values from XML documents using advanced XPath 2.0 expressions. It's ideal for complex queries requiring predicates, functions, or advanced filtering.

Syntax

xpath2('Expression', Content)

Parameters:

  • Expression (string): An XPath 2.0 expression to query the XML, e.g., '/Root/Ids/Id[Name="EmployeeID"]/Value'
  • Content (string): The XML content to query, typically from body() or context()

Common XPath 2.0 patterns:

  • '/Root/Ids/Id[Name="EmployeeID"]/Value' – Select value where Name equals "EmployeeID"
  • '//Id[position() > 1]/Value' – Select values from all Id elements except the first
  • 'string-join(//Value, ", ")' – Concatenate all values with comma separator (XPath 2.0 function)
  • '/Root/Data[matches(@type, "^customer")]' – Use regex matching (XPath 2.0 feature)

Extract from different sources:

  • Extract from message body: xpath2('/Root/Id/Value', body())
  • Extract from message context: xpath2('/Orders/Id', context('MessageContextKey'))
  • Extract from base64-encoded XML: xpath2('/Orders/Id', base64decode(body()))

Next step