---
title: XPath on Message Context Plugin – Extract XML Values from Context Properties
description: Extract unique values from XML stored in a context property with the Nodinite XPath on Message Context Search Field Expression plugin. Set the XPath and the case-sensitive Context key; see a tested order example.
---

# <i class="fal fa-magnifying-glass" aria-hidden="true"></i> XPath on Message Context Search Field Expression Plugin

The **XPath on Message Context** plugin runs an [XPath][] 1.0 expression on XML stored in one context property of a [Log Event][], not on the message body. Use it when a system puts an XML document, such as an order summary, into a context property.

* ✅ Reads one named context property; the message body is ignored  
* ✅ Same XPath rules as the [XPath][] plugin, including element names without namespace prefixes  

![XPath on Message Context expression tested on the XMLContent context property, animated walkthrough (7.12)][4]  
*Animated walkthrough: pick the **XPath on Message Context** type, enter the order id path and the **Context key** `XMLContent`, add that key and its XML value on the **Message Context** tab of **Test Expression**, and test; the **Result** shows two unique matches, 101 and 102.*  

## <i class="fal fa-scale-balanced" aria-hidden="true"></i> When to use it

| Your data | Use |
| --- | --- |
| Plain XML in the message body; you want element or attribute values as they are | [XPath][] |
| Only part of an XML value (a file name in a path, an ID in a formatted string), or tag names inside an XML sub-tree | [XPath with RegEx][] |
| XML stored as escaped text inside an element of another XML message | [XPath on wrapped XPath][XPath on Wrapped XPath] |
| XML stored in a context property instead of the body | **XPath on Message Context** (this page) |
| Full XPath over the whole document (look-back steps, predicates on child elements), or XPath combined with other functions (decode Base64 first, concatenate, compare) | [Formula][] with [xPath2][Formula xPath2] |

When the context value isn't XML, use [Message Context Key][] for the whole value or [RegEx on Message Context][] for part of it; for the other plugins, see [Choose a plugin][].

## <i class="fal fa-code" aria-hidden="true"></i> Expression syntax

<div class="mermaid">
graph LR
    A["fa:fa-key Context key<br/>names the property"] --> B["XML value of<br/>that property"]
    B --> C["XPath<br/>selects values"]
    C --> D["fa:fa-magnifying-glass-plus Unique values"]
    style A fill:#2678BD,color:#fff
    style B fill:#3F827B,color:#fff
    style C fill:#E47528,color:#fff
    style D fill:#93d16d,color:#000
</div>

*The Context key (blue) picks the property; its XML value (teal) is read with the XPath (orange); the matches become the [Search Field][Search Fields] values (green).*  

The plugin shows these fields:

| Field | What goes in it |
| --- | --- |
| **XPath** | The [XPath 1.0][XPath] expression to use on the context value, written from the root without a leading `/` (`Orders/Order/Id`). Element names match without namespace prefixes; the supported syntax is listed in [Allowed XPath expressions][]. |
| **Context key** | The name of the context property that holds the XML. The name is case sensitive. |

Duplicates are collapsed into unique values ([How expressions run][]). Pick the plugin in the **Type** list when you [add or manage a Search Field][Add or manage Search Field]. To test it, add the key and its XML value on the **Message Context** tab of the **Test Expression** tab ([Test Your Expression][]); the body may stay empty.

![Type list filtered on XPath on M, the XPath on Message Context plugin selected (7.12)][1]  
*Selecting **XPath on Message Context** in the **Type** list.*  

## <i class="fal fa-list-ol" aria-hidden="true"></i> Examples

### Example 1: Get the order IDs from an XML context property

#### Input

| Context key | Value |
| --- | --- |
| `XMLContent` | `<ns0:Orders xmlns:ns0="Common.Schemas/Nodinite/1.0"><Order><Id>101</Id></Order><Order><Id>102</Id></Order></ns0:Orders>` |

#### Expression

| Field | Value |
| --- | --- |
| XPath | `Orders/Order/Id` |
| Context key | `XMLContent` |

#### Result

```text
101
102
```

![Test Expression tab with XPath on Message Context returning 101 and 102 from the XMLContent context key (7.12)][2]  
*XPath `Orders/Order/Id` on the `XMLContent` context key returns 2 unique matches; the Message Context tab holds the test value.*  

## <i class="fal fa-triangle-exclamation" aria-hidden="true"></i> Limitations

* The Context key must match the property name exactly, including case. If the property is missing or its value isn't XML, the expression returns no value.
* Context properties and the reserved keys are described in [Context Options][]. Properties that the [ContextPropertiesFilters][] [System Parameter][System Parameters] removes aren't kept, so don't base a Search Field on them.
* The XPath uses the same forward-only reader as the [XPath][] plugin, so only the syntax in [Allowed XPath expressions][] works.

An expression that matches nothing gives this result in the test:

![Test result: Processed with warning, The Expression yields no result (7.12)][3]  
*No match: the test reports **Processed with warning: The Expression yields no result** instead of values.*  

## <i class="fal fa-hand-point-right" aria-hidden="true"></i> Next Steps

* <i class="fal fa-plus" aria-hidden="true"></i> [Add or manage Search Field][]  
* <i class="fal fa-flask" aria-hidden="true"></i> [Test Your Expression][]  
* <i class="fal fa-list-check" aria-hidden="true"></i> [Allowed XPath expressions][]  
* <i class="fal fa-table-list" aria-hidden="true"></i> [Add or manage Log View][]  

## <i class="fal fa-link-horizontal" aria-hidden="true"></i> Related Topics

* <i class="fal fa-magnifying-glass" aria-hidden="true"></i> [XPath][]  
* <i class="fal fa-magnifying-glass" aria-hidden="true"></i> [XPath with RegEx][]  
* <i class="fal fa-magnifying-glass" aria-hidden="true"></i> [XPath on wrapped XPath][XPath on Wrapped XPath]  
* <i class="fal fa-key" aria-hidden="true"></i> [Message Context Key][]  
* <i class="fal fa-key" aria-hidden="true"></i> [RegEx on Message Context][]  
* <i class="fal fa-key" aria-hidden="true"></i> [RegEx on Message Context with capturing groups][]  
* <i class="fal fa-function" aria-hidden="true"></i> [Formula xPath2][]  
* <i class="fal fa-filter" aria-hidden="true"></i> [ContextPropertiesFilters][]  
* <i class="fal fa-signs-post" aria-hidden="true"></i> [Choose a plugin][]  
* <i class="fal fa-magnifying-glass-plus" aria-hidden="true"></i> [Search Field Expressions][]  
* <i class="fal fa-magnifying-glass-plus" aria-hidden="true"></i> [Search Fields][]  
* <i class="fal fa-file" aria-hidden="true"></i> [Message Types][]  
* <i class="fal fa-table-list" aria-hidden="true"></i> [Log Views][]  

[1]:https://docs.nodinite.com/media/Documentation%20Pictures/IM/WebClient/Admin/Log/Search%20Fields/Plugins/XPath%20on%20Message%20Context/Select.png
[2]:https://docs.nodinite.com/media/Documentation%20Pictures/IM/WebClient/Admin/Log/Search%20Fields/Plugins/XPath%20on%20Message%20Context/Example1.png
[3]:https://docs.nodinite.com/media/Documentation%20Pictures/IM/WebClient/Admin/Log/Search%20Fields/NoResult.png
[4]:https://docs.nodinite.com/media/Documentation%20Pictures/IM/WebClient/Admin/Log/Search%20Fields/Plugins/Expression_XPathMessageContext.gif

[Add or manage Log View]:https://docs.nodinite.com/administration/log-management/log-views/features/add-or-manage-log-view/
[Add or manage Search Field]:https://docs.nodinite.com/administration/log-management/search-fields/features/add-or-manage-search-field/
[Allowed XPath expressions]:https://docs.nodinite.com/administration/log-management/search-fields/troubleshooting/allowed-xpath-expressions/
[Choose a plugin]:https://docs.nodinite.com/administration/log-management/search-fields/features/search-field-expressions/overview/#fa-signs-post-choose-a-plugin
[Context Options]:https://docs.nodinite.com/core-services/log-event/features/context-options/
[ContextPropertiesFilters]:https://docs.nodinite.com/administration/settings/system-parameters/contextpropertiesfilters/
[Formula]:https://docs.nodinite.com/administration/log-management/search-fields/features/search-field-expressions/formula/overview/
[Formula xPath2]:https://docs.nodinite.com/administration/log-management/search-fields/features/search-field-expressions/formula/extract/xpath2/
[How expressions run]:https://docs.nodinite.com/administration/log-management/search-fields/features/search-field-expressions/overview/#fa-gears-how-expressions-run
[Log Event]:https://docs.nodinite.com/core-services/log-event/overview/
[Log Views]:https://docs.nodinite.com/administration/log-management/log-views/features/what-is-a-log-view/
[Message Context Key]:https://docs.nodinite.com/administration/log-management/search-fields/features/search-field-expressions/message-context-key/
[Message Types]:https://docs.nodinite.com/repository-model/message-types/overview/
[RegEx on Message Context]:https://docs.nodinite.com/administration/log-management/search-fields/features/search-field-expressions/regex-on-message-context/
[RegEx on Message Context with capturing groups]:https://docs.nodinite.com/administration/log-management/search-fields/features/search-field-expressions/regex-on-message-context-with-capturing-groups/
[Search Field Expressions]:https://docs.nodinite.com/administration/log-management/search-fields/features/search-field-expressions/overview/
[Search Fields]:https://docs.nodinite.com/administration/log-management/search-fields/features/what-is-a-search-field/
[System Parameters]:https://docs.nodinite.com/administration/settings/system-parameters/overview/
[Test Your Expression]:https://docs.nodinite.com/administration/log-management/search-fields/features/add-or-manage-search-field/#test-your-expression
[XPath]:https://docs.nodinite.com/administration/log-management/search-fields/features/search-field-expressions/xpath/
[XPath on Wrapped XPath]:https://docs.nodinite.com/administration/log-management/search-fields/features/search-field-expressions/xpath-on-wrapped-xpath/
[XPath with RegEx]:https://docs.nodinite.com/administration/log-management/search-fields/features/search-field-expressions/xpath-with-regex/