---
title: "Formula - xPath: Extract Values from XML with XPath 1.0"
description: The xPath Formula function returns the values in XML content that match an XPath 1.0 expression, using a forward-only reader. Includes syntax, parameters, and examples from the body, base64-encoded XML, and a context property.
---

# <i class="fal fa-function" aria-hidden="true"></i> Formula - XPath

The `xPath` [Formula][] function returns the values in XML content that match an XPath 1.0 expression.

![Read the order id from an Order Entry XML event with xPath, animated walkthrough (7.12)][36]  
*Animated walkthrough: `xPath('OrderEntry/OrderHeader/OrderId', body)` on the Order Entry XML of the [Order-to-Cash demo][] returns `ORD-10005`. The XML has a default namespace, and the path matches without a prefix.*  

<aside aria-label="Note" class="nodinite-note nodinite-note--note">
<p class="nodinite-note__label" aria-hidden="true"><i class="far fa-fw fa-note"></i> Note</p>
<div class="nodinite-note__content"><p><code>xPath</code> reads XML with a forward-only reader and supports the XPath 1.0 subset listed in <a href="https://docs.nodinite.com/administration/log-management/search-fields/troubleshooting/allowed-xpath-expressions/">Allowed XPath expressions</a>. For look-back steps or predicates on child elements, use <a href="https://docs.nodinite.com/administration/log-management/search-fields/features/search-field-expressions/formula/extract/xpath2/">xPath2</a>, which reads the whole document.</p></div>
</aside>

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

```text
xPath('expression', content)
```

### Parameters

|Parameter|Required|Description|  
|---|---|---|  
|`'expression'`|Yes|An XPath 1.0 expression in single quotes, such as `'/Orders/Id'`. A literal `'` inside it is written `''`.|  
|`content`|Yes|The XML text: [body][], [context][Context], or the result of another function, such as [base64decode][] (see [Formula language rules][]).|  

### Returns

The text value of every matching element or attribute, one value each; duplicates are collapsed. When nothing matches, nothing is returned.

Element names match without namespace prefixes or declarations: `Orders/Order/Id` matches `<ns0:Orders xmlns:ns0="…">` (see [Formula language rules][]).

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

### Example 1: Read an element from the body

#### Input

```xml
<Id>3</Id>
```

#### Formula

```text
xPath('/Id', body)
```

#### Result

```text
3
```

![Formula xPath expression returning 3 from an XML message body in the Test Expression tab (7.12)][35]  
*`/Id` selects the root element `Id` and returns its text.*  

### Example 2: Read all order IDs from base64-encoded XML

#### Input

```text
PE9yZGVycz4KICA8SWQ+MzwvSWQ+CiAgPElkPjY8L0lkPgo8L09yZGVycz4=
```

The body decodes to:

```xml
<Orders>
  <Id>3</Id>
  <Id>6</Id>
</Orders>
```

#### Formula

```text
xPath('/Orders/Id', base64decode(body))
```

#### Result

```text
3
6
```

![Formula xPath over base64decode of the body returning the order IDs 3 and 6 in the Test Expression tab (7.12)][33]  
*[base64decode][] turns the body into XML first; `xPath` then returns both `Id` values.*  

### Example 3: Read XML stored in a context property

#### Input

|Key|Value|  
|---|---|  
|id|`<Id>3</Id>`|  

#### Formula

```text
xpath('/Id',context('id'))
```

#### Result

```text
3
```

![Test Expression tab: xpath('/Id',context('id')) reads the XML in the id context property and returns 3 (7.12)][34]  
*The XML in the `id` context property is queried like a message body.*  

### Example 4: Pick an attribute by its content and clean it up

#### Input

```xml
<Root>
  <Data Data="SENDERID:13"/>
  <Data Data="VATNO:SE19840410-1337"/>
  <Data Data="RECEIVERID:37"/>
</Root>
```

#### Formula

```text
replace('VATNO:', '', xPath('/Root/Data[contains(@Data, ''VATNO'')]/@Data', body))
```

#### Result

```text
SE19840410-1337
```

The predicate keeps the `Data` element whose attribute contains `VATNO`; the doubled `''VATNO''` is the escaped single quote inside the quoted XPath, so XPath receives `'VATNO'`. [replace][] then removes the `VATNO:` prefix.

![Formula replace around xPath returning the VAT number SE19840410-1337 from a Data attribute in the Test Expression tab (7.12)][ex4]  
*Of the three `Data` attributes, only the `VATNO` one is selected, and `replace` strips its prefix to leave the bare VAT number.*  

## <i class="fal fa-circle-info" aria-hidden="true"></i> Notes

* Expressions that look back, such as `..` or `parent::`, return no values, and the test bench shows the warning *xpath is not supported!*; see [Allowed XPath expressions][] for what the forward-only reader supports.
* A predicate on a child element, such as `Orders/Order[Id=2]/City`, isn't supported either: the test bench shows *Can't get the child value*. An attribute test such as `[contains(@Data, ''VATNO'')]` works (Example 4).
* A leading `//`, such as `//Id`, returns nothing. Write the path from the root.
* `xPath` is the better choice for large XML; use [xPath2][] only when you need what the forward-only reader refuses.
* For one XPath on the body, the [XPath plugin][] does the same without a formula; for XML in a context value, use the [XPath on Message Context plugin][]. See [Choose a plugin][].

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

* <i class="fal fa-magnifying-glass-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-hard-drive" 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-filter" aria-hidden="true"></i> [Extract functions][Extract Group]  
* <i class="fal fa-file-csv" aria-hidden="true"></i> [csv][]  
* <i class="fal fa-sitemap" aria-hidden="true"></i> [jsonPath][]  
* <i class="fal fa-key" aria-hidden="true"></i> [jsonPathKey][]  
* <i class="fal fa-text-slash" aria-hidden="true"></i> [regex][]  
* <i class="fal fa-layer-group" aria-hidden="true"></i> [regexGroup][]  
* <i class="fal fa-database" aria-hidden="true"></i> [sqllookup][]  
* <i class="fal fa-code" aria-hidden="true"></i> [xPath2][]  
* <i class="fal fa-list-check" aria-hidden="true"></i> [Allowed XPath expressions][]  
* <i class="fal fa-function" aria-hidden="true"></i> [Formula][]  
* <i class="fal fa-scroll" aria-hidden="true"></i> [Formula language rules][]  
* <i class="fal fa-puzzle-piece" aria-hidden="true"></i> [Search Field Expressions][]  
* <i class="fal fa-magnifying-glass" aria-hidden="true"></i> [XPath plugin][]  
* <i class="fal fa-magnifying-glass" aria-hidden="true"></i> [XPath on Message Context plugin][]  

[33]:https://docs.nodinite.com/media/Documentation%20Pictures/IM/WebClient/Admin/Log/Search%20Fields/Plugins/Formula/Extract/xpath_nestingFunction_body.png
[34]:https://docs.nodinite.com/media/Documentation%20Pictures/IM/WebClient/Admin/Log/Search%20Fields/Plugins/Formula/Extract/xpath_simpleXML_messagcontext.png
[35]:https://docs.nodinite.com/media/Documentation%20Pictures/IM/WebClient/Admin/Log/Search%20Fields/Plugins/Formula/Extract/xpath_simpleParameter_body.png
[36]:https://docs.nodinite.com/media/Documentation%20Pictures/IM/WebClient/Admin/Log/Search%20Fields/Plugins/Formula/Formula_XPath.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/
[base64decode]:https://docs.nodinite.com/administration/log-management/search-fields/features/search-field-expressions/formula/convert/base64decode/
[body]:https://docs.nodinite.com/administration/log-management/search-fields/features/search-field-expressions/formula/source/body/
[Choose a plugin]:https://docs.nodinite.com/administration/log-management/search-fields/features/search-field-expressions/overview/#fa-signs-post-choose-a-plugin
[Context]:https://docs.nodinite.com/administration/log-management/search-fields/features/search-field-expressions/formula/source/context/
[csv]:https://docs.nodinite.com/administration/log-management/search-fields/features/search-field-expressions/formula/extract/csv/
[ex4]:https://docs.nodinite.com/media/Documentation%20Pictures/IM/WebClient/Admin/Log/Search%20Fields/Plugins/Formula/Extract/xpath_example4.png
[Extract Group]:https://docs.nodinite.com/administration/log-management/search-fields/features/search-field-expressions/formula/overview/#extract
[Formula]:https://docs.nodinite.com/administration/log-management/search-fields/features/search-field-expressions/formula/overview/
[Formula language rules]:https://docs.nodinite.com/administration/log-management/search-fields/features/search-field-expressions/formula/overview/#fa-scroll-formula-language-rules
[jsonPath]:https://docs.nodinite.com/administration/log-management/search-fields/features/search-field-expressions/formula/extract/jsonpath/
[jsonPathKey]:https://docs.nodinite.com/administration/log-management/search-fields/features/search-field-expressions/formula/extract/jsonpathkey/
[Order-to-Cash demo]:https://docs.nodinite.com/repository-model/bpms/examples/order-to-cash/generate-o2c-demo-data/
[regex]:https://docs.nodinite.com/administration/log-management/search-fields/features/search-field-expressions/formula/extract/regex/
[regexGroup]:https://docs.nodinite.com/administration/log-management/search-fields/features/search-field-expressions/formula/extract/regexgroup/
[replace]:https://docs.nodinite.com/administration/log-management/search-fields/features/search-field-expressions/formula/alter/replace/
[Search Field Expressions]:https://docs.nodinite.com/administration/log-management/search-fields/features/search-field-expressions/overview/
[sqllookup]:https://docs.nodinite.com/administration/log-management/search-fields/features/search-field-expressions/formula/extract/sqllookup/
[Test Your Expression]:https://docs.nodinite.com/administration/log-management/search-fields/features/add-or-manage-search-field/#test-your-expression
[XPath on Message Context plugin]:https://docs.nodinite.com/administration/log-management/search-fields/features/search-field-expressions/xpath-on-message-context/
[XPath plugin]:https://docs.nodinite.com/administration/log-management/search-fields/features/search-field-expressions/xpath/
[XPath2]:https://docs.nodinite.com/administration/log-management/search-fields/features/search-field-expressions/formula/extract/xpath2/