XPath formula function
Info
Support for XPath 1.0. For XPath 2.0, please review the XPath2 user-guide.
The XPath Formula function is used to extract unique values from data in XML format using valid XPath 1.0 based expressions.
Syntax
The XML content may originate from any of the following sources:
Content from Message Body:
XPath('Expression ',body)
Content from Message Context:
XPath('Expression',context('MessageContextKey'))
Result from previous Formula operation
XPath('Expression',SomeOtherFormulaFunction(Content))
Quick example
Below is a simple example using XML data and an XPath expression to extract data: For other and advanced examples, please scroll down on this page to the Examples section.
Input | Expression | Result |
---|---|---|
|
|
|
XML data from message body | XPath expression | Unique values |
Features
- Extract single or multiple unique values from Content.
- Uses many regular XPath expression as defined by W3C.
- Can be applied to any valid Content that returns XML data structure; review Formula user guide for a complete list of functions.
Important
This plugin loads the entire message into RAM, so make sure to apply this function only on small messages.
How to use
To use the XPath function; The Content parameter must contain a valid XML data structure (otherwise, it will fail, and you will end up with no or garbage result).
First, you must configure the Search Field Expressions to use the Formula plugin:
- Input a proper XML Content
- Message Body or Message Context
- Select Formula as the expression type plugin
- Write down the XPath expression to use in the 'Expression' text area
Examples
Below are some common examples of how to use the XPath function.
Content from Message Body
In this example, the data comes from the message body. The data is base64encoded and must be decoded into its XML representation before applying the XPath 1.0 expression to get the value of interest.
Input | Expression | Result |
---|---|---|
|
|
|
Base 64 encoded XML data from message body | combined expression using the XPath method on the result from the base64decode expression | Unique values |
Content from Message Context
In this example, the data comes from a message context field. The nested XPath expression gets the unique values of interest.
Input | Expression | Result |
---|---|---|
|
|
|
XML data from message context | XPath expression | Unique values |
Contains based XPath example
In this example, we get the value from a collection of attributes in some XML structure using the contains
XPath method. The retreived value is then cleansed from its prefix (VATNO:).
Input | Expression | Result |
---|---|---|
|
|
|
XML data from message body | combined expression using the replace method on the result from the XPath expression | Unique values |
Note
Do note the attribute used in the expression is escaped using two single quotes (
´´
)
Next Step
How to Add or manage Search Fields
How to Add or manage Log Views
Related
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?