- 5 minutes to read

XPath search field expression type plugin

Use this plugin to extract values from large XML messages

New 6.1
Support for multiple XPath expressions using the | character.

The Nodinite XPath Search Field Expression Type plugin can be used to find one or more unique values from elements and attributes in your logged XML documents.

A Logged message comes from a Log Event that is part of the Logging feature of Nodinite and the Search Fields are further used within self-service enabled Log Views for your business.

Quick example

Let's get you started with the following simple demonstration example valid for this search field plugin. For other and more advanced examples please scroll down on this page to the Examples section.

Input Expression Result
<Orders>
    <Order>
        <Id>101</Id>
    </Order>
    <Order>
        <Id>102</Id>
    </Order>
<Orders>
Orders/Order/Id
101
102
XML Data Xpath expression Unique values

Features

This plugin uses a high-performance read-only fast forward-only stream reader. Based on Microsoft's XPathReader.

  • Extract single or multiple unique values from XML messages (payload)
  • Uses many regular XPath expressions as defined by W3C
  • The XPathReader provides the ability to perform XPath over XML documents in a streaming manner (large messages are thereby supported)
    • The XPathReader provides the ability to filter and process large XML documents in an efficient manner using an XPath-aware XmlReader. With the XPathReader, one can sequentially process a large document and extract an identified sub-tree matched by the user-configured XPath expression

Not all types of XPaths can be evaluated using this XPath extractor, due to its forward only stream reader.


How to use

To extract values from XML messages you must first configure the Search Field, in this example case; The Order Id:

Once a Search Field is configured, values are extracted either during normal processing or from user initiated re-index operations. Extracted values are persisted and stored for as long as the days to keep events property on the Message Type is configured.

Test Expression

You can test an expression when configuring a Search Field in the 'Test Expression' tab

  1. Enter an appropriate payload in the 'Message Body' tab
  2. Select the 'XPath' expression type plugin
    Select XPath Plugin
  3. Enter valid XPath expression (You can also click on elements/attributes to get a suggestion)
  4. Review the result/output, rewrite the code in step 3 until you get the data you seek

The actual result (values) are extracted by the Logging Service and then presented together with the evaluated processing state and the number of unique matches.

Test expression A valid expression with state output, unique values and total count

If the expression is either invalid or does not match any data, then the following output is presented:
No result
Invalid expression yields no result

Examples

You can find some additional examples of allowed expressions to get you started in the following link: XPath examples

Basic example

To extract order id(s) for the Message Type 'Common.Schemas/Nodinite/1.0#Orders' you can use the following valid expression 'Orders/Order/Id'. This expression yields the unique values 101 and 102

graph LR subgraph "Search Fields" sf(fal:fa-search-plus Order Number) end subgraph "Search Field Expressions" sfe(fal:fa-flask XPath plugin) end subgraph "MessageTypes" mt1(fal:fa-file Orders) end sf --- sfe sfe ---|Expression| mt1

Message Body

<ns0:Orders xmlns:ns0="Common.Schemas/Nodinite/1.0">
    <Order>
        <Id>101</Id>
        <Amount>1000</Amount>
        <City>Karlstad</City>
    </Order>
    <Order>
        <Id>102</Id>
        <Amount>10</Amount>
        <City>Stockholm</City>
    </Order>
</ns0:Orders>

Expression

Orders/Order/Id

Order-/Order-Response example

You can probably apply this solution pattern on many other common integration scenarios

Let's say there are multiple Message Types where the structure is very similar and maybe the only difference is the name of the root node.

graph LR subgraph "Search Fields" sf(fal:fa-search-plus Order Number) end subgraph "Search Field Expressions" sfe(fal:fa-flask XPath plugin) end subgraph "MessageTypes" mt1(fal:fa-file Order) mt2(fal:fa-file OrderResponse) end sf --- sfe sfe --- |Expression 1| mt1 sfe --- |Expression 1| mt2

To extract the order id(s) for both Message Types:

  • Common.Schemas/Nodinite/1.0#Orders and
  • Common.Schemas/Nodinite/1.0#OrderResponse

Use the following valid XPath expression 'node()/Order/Id'. This expression yields the unique values 101 and 102 for both messages.

This means that you only need just one (1) search field expression applied on the two (2) Message Types. Using this technique saves your time and helps you keep related configurations tight and together.

Order OrderResponse
<ns0:Orders xmlns:ns0="Common.Schemas/Nodinite/1.0">
    <Order>
        <Id>101</Id>
        <Amount>1000</Amount>
        <City>Karlstad</City>
    </Order>
    <Order>
        <Id>102</Id>
        <Amount>10</Amount>
        <City>Stockholm</City>
    </Order>
</ns0:Orders>
<ns0:OrderResponse xmlns:ns0="Common.Schemas/Nodinite/1.0">
    <Order>
        <Id>101</Id>
        <Status>OK</Status>
    </Order>
    <Order>
        <Id>102</Id>
        <Status>Failed</Status>
    </Order>
</ns0:OrderResponse>

Expression

node()/Order/Id

Next Step

How to Add or manage Search Fields
How to Add or manage Log Views

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?