- 0 minutes to read

Formula - XPath

Easily extract values from XML messages using the Nodinite XPath Formula plugin. This page shows how to use XPath 1.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 a single formula from any Payload or Context in any Log Event
  • βœ… Standard XPath 1.0 expressions for flexible 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 1.0. For XPath 2.0, please review the XPath2 user-guide.


What does the XPath Formula do?

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


How it works: Input ➜ XPath ➜ Result

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

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


Examples

Below are practical examples showing how to extract values from XML using XPath 1.0 expressions.

Example 1: Extracting a Value from XML Body

Input - Example 1

<Id>3</Id>

Formula Expression - Example 1

XPath('/Id', body())

Result - Example 1

3

Example 2: Extracting Multiple Values from Base64-encoded XML

Suppose your message body contains base64-encoded XML.

Input - Example 2

PE9yZGVycz48SWQ+MzwvSWQ+PElkPjY8L0lkPjwvT3JkZXJzPg==

Formula Expression - Example 2

XPath('/Orders/Id', base64decode(body()))

Result - Example 2

3
6

XPathNodes_multiple_body_nestingFunction

Example: Extracting multiple values from base64-encoded XML using XPath

Example 3: Extracting a Value from Message Context

Suppose you have a message context value with the key id containing XML content.

Input - Example 3

<Id>3</Id>

Formula Expression - Example 3

XPath('/Id', context('id'))

Result - Example 3

3

XPath_simpleParameter_MessageContext

Example: Extracting a value from message context using XPath

Example 4: Using contains() in XPath

Suppose you want to extract a value from an attribute in an XML structure using the contains XPath method and then cleanse the result.

Input - Example 4

<Root>
  <Data Data="SENDERID:13"/>
  <Data Data="VATNO:SE19840410-1337"/>
  <Data Data="RECEIVERID:37"/>
</Root>

Formula Expression - Example 4

replace('VATNO:', '', XPath('/Root/Data[contains(@Data, ''VATNO'')]/@Data', body()))

Result - Example 4

SE19840410-1337

Features

The XPath 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 1.0
  • Use standard XPath expressions as defined by W3C
  • Works with message body, Context, or results from other Formula functions
  • Ensures data integrity across integrated systems

Important

The XPath plugin loads the entire message into RAM. Only use this function on small messages to avoid performance issues.


How to use

The XPath formula extracts values from XML documents using standard XPath 1.0 expressions. It's ideal for querying structured XML data and extracting specific elements or attributes.

Syntax

XPath('Expression', Content)

Parameters:

  • Expression (string): An XPath 1.0 expression to query the XML, e.g., '/Orders/Id', '//Data[@type="customer"]'
  • Content (string): The XML content to query, typically from body() or context()

Common XPath patterns:

  • '/Id' – Select the root-level <Id> element
  • '/Orders/Id' – Select all <Id> elements under <Orders>
  • '//Data[@type="customer"]' – Select all <Data> elements with type="customer" attribute
  • '/Root/Data[contains(@Data, "VATNO")]/@Data' – Select Data attribute where it contains "VATNO"

Extract from different sources:

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

Next step