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
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
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
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 withtype="customer"
attribute'/Root/Data[contains(@Data, "VATNO")]/@Data'
β SelectData
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
- How to Add or manage Search Fields
- How to Add or manage Log Views
Related Topics
- body β Extract body from the Log Event
- Context β Extract context values from the Log Event
- XPath2 β Extract values from XML using XPath 2.0 expressions
- base64decode β Decode base64-encoded content
- jsonPath β Extract values from JSON using JSONPath expressions
- Expression Type Plugins are used in Search Fields
- What are Search Fields?
- What are Search Field Expressions?
- What are Message Types?
- What are Log Views?