- 0 minutes to read

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:

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
 <Id>3</Id>
XPath('/Id',body)
3
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.
XPathNodes_multiple_body_nestingFunction

Input Expression Result
PE9yZGVycz48SWQ+MzwvSWQ+PElkPjY8L0lkPjwvT3JkZXJzPg==
XPath('/Orders/Id',base64decode(body))
3
6
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.
XPath_simpleParameter_MessageContext

Input Expression Result
<Id>3</Id>
XPath('/Id',context('id'))
3
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
<Root>
  <Data Data="SENDERID:13"/>
  <Data Data="VATNO:SE19840410-1337"/>  
  <Data Data="RECEIVERID:37"/>  
</Root>
replace('VATNO:', '',XPath('/Root/Data[contains(@Data, ''VATNO'')]/@Data',body))
SE19840410-1337
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

Expression Type Plugins are used in Search Fields