Allowed XPath expressions for Search Field Expressions
The four XPath plugins for Search Field Expressions read XML with a forward-only stream reader, so they accept only XPath 1.0 expressions that move forward through the document. This page lists what works, how namespaces are handled, and what to do when your expression isn't supported. It applies to XPath, XPath with RegEx, XPath on Wrapped XPath, and XPath on Message Context.
Why only forward-only XPath works
The Logging Service evaluates the expressions on every logged message. XML messages can be very large, so the XPath plugins use a read-only, forward-only stream reader based on Microsoft's XPathReader instead of loading the whole document. The reader can only move forward through the stream, which keeps memory use low but limits the XPath syntax:
- ✅ Supported: child steps, attributes,
node(),text(), and predicates on attributes of the current element. - ❌ Not supported: anything that needs to look back, such as the parent axis (
parent::node(),..),ancestor::, orpreceding-sibling::.
Allowed XPath expressions: examples
All expressions below work with the forward-only reader.
| Expression | Message | Output |
|---|---|---|
/e |
<e>1</e> |
1 |
child::node() |
<e>1</e> |
1 |
e/child::node() |
<e>1</e> |
1 |
e/a/child::text() |
<e><a>1</a><b>2</b></e> |
1 |
e/a[@name='A']/child::text() |
<e><a name="A">1</a><a name="B">2</a></e> |
1 |
e/a/@name |
<e><a name="A">1</a><a name="B">2</a></e> |
A B |
e/a/attribute::* |
<e><a name="A">1</a><a name="B">2</a></e> |
A B |
Orders/Order/Id |
<ns0:Orders xmlns:ns0="Common.Schemas/Nodinite/1.0"><Order><Id>101</Id></Order></ns0:Orders> |
101 |
Namespaces
The XPath plugins match element names without namespace prefixes or declarations. Write the local element names only: Orders/Order/Id matches <ns0:Orders xmlns:ns0="…">, as the last row of the table shows. Don't add prefixes such as ns0: to the expression. The same rule applies to the Formula function xPath.
When your expression isn't supported
Tip
Always test your XPath expression in the Test Expression tab before you save the Search Field or start a re-index (Test Your Expression).
Important
XPathReader is limited to what the underlying
XmlTextReadercan do, which is move forward through the stream. An expression that needs backward navigation, such asparent::node(), can't be evaluated and returns no values.
- Rewrite the expression to walk forward from the root: select the element you need directly instead of going to a child and back up to its parent.
- Use a predicate on an attribute of the element you select (
e/a[@name='A']) instead of navigating back. - For XPath 2.0 syntax, use the Formula function xPath2.