---
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.
---

# :fa-function: 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.*  

>[!NOTE]
>`xPath` reads XML with a forward-only reader and supports the XPath 1.0 subset listed in [Allowed XPath expressions][]. For look-back steps or predicates on child elements, use [xPath2][], which reads the whole document.

## :fa-code: 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][]).

## :fa-list-ol: 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.*  

## :fa-circle-info: 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][].

## :fa-hand-point-right: Next Steps

* :fa-magnifying-glass-plus: [Add or manage Search Field][]  
* :fa-flask: [Test Your Expression][]  
* :fa-hard-drive: [Add or manage Log View][]  

## :fa-link-horizontal: Related Topics

* :fa-filter: [Extract functions][Extract Group]  
* :fa-file-csv: [csv][]  
* :fa-sitemap: [jsonPath][]  
* :fa-key: [jsonPathKey][]  
* :fa-text-slash: [regex][]  
* :fa-layer-group: [regexGroup][]  
* :fa-database: [sqllookup][]  
* :fa-code: [xPath2][]  
* :fa-list-check: [Allowed XPath expressions][]  
* :fa-function: [Formula][]  
* :fa-scroll: [Formula language rules][]  
* :fa-puzzle-piece: [Search Field Expressions][]  
* :fa-magnifying-glass: [XPath plugin][]  
* :fa-magnifying-glass: [XPath on Message Context plugin][]  

[33]:{ndm}/Documentation%20Pictures/IM/WebClient/Admin/Log/Search%20Fields/Plugins/Formula/Extract/xpath_nestingFunction_body.png
[34]:{ndm}/Documentation%20Pictures/IM/WebClient/Admin/Log/Search%20Fields/Plugins/Formula/Extract/xpath_simpleXML_messagcontext.png
[35]:{ndm}/Documentation%20Pictures/IM/WebClient/Admin/Log/Search%20Fields/Plugins/Formula/Extract/xpath_simpleParameter_body.png
[36]:{ndm}/Documentation%20Pictures/IM/WebClient/Admin/Log/Search%20Fields/Plugins/Formula/Formula_XPath.gif

[Add or manage Log View]:{ndr}/Administration/1.%20Log%20Management/1.%20Log%20Views/Features/Add%20or%20Manage%20Log%20View.md
[Add or manage Search Field]:{ndr}/Administration/1.%20Log%20Management/2.%20Search%20Fields/Features/Add%20or%20manage%20Search%20Field.md
[Allowed XPath expressions]:{ndr}/Administration/1.%20Log%20Management/2.%20Search%20Fields/Troubleshooting/Allowed%20XPath%20expressions.md
[base64decode]:{ndr}/Administration/1.%20Log%20Management/2.%20Search%20Fields/Features/Search%20Field%20Expressions/Formula/Convert/base64decode.md
[body]:{ndr}/Administration/1.%20Log%20Management/2.%20Search%20Fields/Features/Search%20Field%20Expressions/Formula/Source/body.md
[Choose a plugin]:{ndr}/Administration/1.%20Log%20Management/2.%20Search%20Fields/Features/Search%20Field%20Expressions/Overview.md#fa-signs-post-choose-a-plugin
[Context]:{ndr}/Administration/1.%20Log%20Management/2.%20Search%20Fields/Features/Search%20Field%20Expressions/Formula/Source/context.md
[csv]:{ndr}/Administration/1.%20Log%20Management/2.%20Search%20Fields/Features/Search%20Field%20Expressions/Formula/Extract/csv.md
[ex4]:{ndm}/Documentation%20Pictures/IM/WebClient/Admin/Log/Search%20Fields/Plugins/Formula/Extract/xpath_example4.png
[Extract Group]:{ndr}/Administration/1.%20Log%20Management/2.%20Search%20Fields/Features/Search%20Field%20Expressions/Formula/Overview.md#extract
[Formula]:{ndr}/Administration/1.%20Log%20Management/2.%20Search%20Fields/Features/Search%20Field%20Expressions/Formula/Overview.md
[Formula language rules]:{ndr}/Administration/1.%20Log%20Management/2.%20Search%20Fields/Features/Search%20Field%20Expressions/Formula/Overview.md#fa-scroll-formula-language-rules
[jsonPath]:{ndr}/Administration/1.%20Log%20Management/2.%20Search%20Fields/Features/Search%20Field%20Expressions/Formula/Extract/jsonPath.md
[jsonPathKey]:{ndr}/Administration/1.%20Log%20Management/2.%20Search%20Fields/Features/Search%20Field%20Expressions/Formula/Extract/JsonPathKey.md
[Order-to-Cash demo]:{ndr}/Repository%20Model/BPMs/Examples/Order-to-Cash/Generate-O2C-Demo-Data.md
[regex]:{ndr}/Administration/1.%20Log%20Management/2.%20Search%20Fields/Features/Search%20Field%20Expressions/Formula/Extract/regex.md
[regexGroup]:{ndr}/Administration/1.%20Log%20Management/2.%20Search%20Fields/Features/Search%20Field%20Expressions/Formula/Extract/regexGroup.md
[replace]:{ndr}/Administration/1.%20Log%20Management/2.%20Search%20Fields/Features/Search%20Field%20Expressions/Formula/Alter/replace.md
[Search Field Expressions]:{ndr}/Administration/1.%20Log%20Management/2.%20Search%20Fields/Features/Search%20Field%20Expressions/Overview.md
[sqllookup]:{ndr}/Administration/1.%20Log%20Management/2.%20Search%20Fields/Features/Search%20Field%20Expressions/Formula/Extract/sqllookup.md
[Test Your Expression]:{ndr}/Administration/1.%20Log%20Management/2.%20Search%20Fields/Features/Add%20or%20manage%20Search%20Field.md#test-your-expression
[XPath on Message Context plugin]:{ndr}/Administration/1.%20Log%20Management/2.%20Search%20Fields/Features/Search%20Field%20Expressions/XPath%20on%20Message%20Context.md
[XPath plugin]:{ndr}/Administration/1.%20Log%20Management/2.%20Search%20Fields/Features/Search%20Field%20Expressions/XPath.md
[XPath2]:{ndr}/Administration/1.%20Log%20Management/2.%20Search%20Fields/Features/Search%20Field%20Expressions/Formula/Extract/xPath2.md