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
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: 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
- 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
- xpath β Extract values from XML using XPath 1.0 expressions (less resource-intensive)
- 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?
