---
title: "Formula - xPath2: Extract Values from XML with Full XPath"
description: "The xPath2 Formula function returns the values in XML content that match a full XPath 1.0 expression over the whole document, including look-back steps and predicates on child elements that the forward-only xPath function can't evaluate. Includes syntax, parameters, namespaces, and an example."
---

# :fa-function: Formula - xpath2

The `xPath2` [Formula][] function returns the values in XML content that match an [XPath][XPath plugin] expression evaluated over the whole document: full XPath 1.0, with every axis and predicates on child elements. Despite its name, it isn't XPath 2.0.

![Read an employee id by the name next to it with xPath2, where xPath refuses, animated walkthrough (7.12)][2]  
*Animated walkthrough: on a logged Contoso HR message (the input of Example 1 below), `xPath2('/Root/Ids/Id[Name=''EmployeeID'']/Value', body)` returns `1337` in the [Test Expression][Test Your Expression] tab. The same expression with [xPath][] is refused: *Can't get the child value*.*  

>[!NOTE]
>Use [xPath][] when its forward-only reader is enough (see [Allowed XPath expressions][]); it is the lighter choice for large XML. Use `xPath2` when the expression needs more, such as a look-back step (`..`) or a predicate on a child element.

## :fa-code: Syntax

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

### Parameters

|Parameter|Required|Description|  
|---|---|---|  
|`'expression'`|Yes|An XPath 1.0 expression in single quotes, with the document's namespace prefixes (see [Namespaces](#fa-sitemap-namespaces)). A literal `'` inside it is written `''`, as in `[Name=''EmployeeID'']`.|  
|`content`|Yes|The XML text: [body][], [context][Context], or the result of another function, such as [base64decode][] (see [Formula language rules][]).|  

### Returns

The inner XML of every matching node, one value each: the text for an element without child elements, and markup (`<Name>EmployeeID</Name>…`) for an element with child elements. Duplicates are collapsed: `xPath2('/a/b', body)` on `<a><b>7</b><b>7</b></a>` returns one `7`. When nothing matches, nothing is returned.

## :fa-sitemap: Namespaces

Unlike [xPath][], `xPath2` needs the namespace prefixes the document uses:

|XML|Expression|Result|  
|---|---|---|  
|`<ns0:Orders xmlns:ns0="…"><Order><Id>101</Id></Order></ns0:Orders>`|`xPath2('/ns0:Orders/Order/Id', body)`|`101`|  
|The same XML|`xPath2('/Orders/Order/Id', body)`|Nothing|  
|`<OrderEntry xmlns="…"><OrderHeader><OrderId>ORD-10005</OrderId>…`|`xPath2('//*[local-name()=''OrderId'']', body)`|`ORD-10005`|  

With a default namespace (`xmlns="…"`), unprefixed names never match; use `local-name()` as in the last row.

## :fa-list-ol: Examples

### Example 1: Read a value by the name next to it

#### Input

```xml
<Root>
    <Ids>
        <Id>
            <Name>EmployeeID</Name>
            <Value>1337</Value>
        </Id>
        <Id>
            <Name>Company</Name>
            <Value>ACME</Value>
        </Id>
    </Ids>
</Root>
```

#### Formula

```text
xPath2('/Root/Ids/Id[Name=''EmployeeID'']/Value', body)
```

#### Result

```text
1337
```

![Formula xPath2 expression with a child-element predicate returning 1337 in the Test Expression tab][1]  
*The predicate `[Name='EmployeeID']` tests a child element of `Id`, then the expression returns the sibling `Value`.*  

## :fa-circle-info: Notes

* The predicate in the example tests a child element, which the forward-only reader of [xPath][] doesn't support: `xPath` refuses it with *Can't get the child value*. The forward-only reader supports predicates on attributes of the current element only.
* `xPath2` loads the whole document in memory instead of reading it forward, so expect it to use more memory than `xPath` on large messages.

## :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: [xPath][]  
* :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][]  

[1]:{ndm}/Documentation%20Pictures/IM/WebClient/Admin/Log/Search%20Fields/Plugins/Formula/Extract/Xpath2LookBehindExample.png
[2]:{ndm}/Documentation%20Pictures/IM/WebClient/Admin/Log/Search%20Fields/Plugins/Formula/Extract/Formula_xPath2.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
[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
[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
[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
[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]:{ndr}/Administration/1.%20Log%20Management/2.%20Search%20Fields/Features/Search%20Field%20Expressions/Formula/Extract/xPath.md
[XPath plugin]:{ndr}/Administration/1.%20Log%20Management/2.%20Search%20Fields/Features/Search%20Field%20Expressions/XPath.md