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

# <i class="fal fa-function" aria-hidden="true"></i> 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*.*  

<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>Use <a href="https://docs.nodinite.com/administration/log-management/search-fields/features/search-field-expressions/formula/extract/xpath/">xPath</a> when its forward-only reader is enough (see <a href="https://docs.nodinite.com/administration/log-management/search-fields/troubleshooting/allowed-xpath-expressions/">Allowed XPath expressions</a>); it is the lighter choice for large XML. Use <code>xPath2</code> when the expression needs more, such as a look-back step (<code>..</code>) or a predicate on a child element.</p></div>
</aside>

## <i class="fal fa-code" aria-hidden="true"></i> 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.

## <i class="fal fa-sitemap" aria-hidden="true"></i> 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.

## <i class="fal fa-list-ol" aria-hidden="true"></i> 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`.*  

## <i class="fal fa-circle-info" aria-hidden="true"></i> 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.

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

[1]:https://docs.nodinite.com/media/Documentation%20Pictures/IM/WebClient/Admin/Log/Search%20Fields/Plugins/Formula/Extract/Xpath2LookBehindExample.png
[2]:https://docs.nodinite.com/media/Documentation%20Pictures/IM/WebClient/Admin/Log/Search%20Fields/Plugins/Formula/Extract/Formula_xPath2.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/
[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/
[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/
[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/
[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]:https://docs.nodinite.com/administration/log-management/search-fields/features/search-field-expressions/formula/extract/xpath/
[XPath plugin]:https://docs.nodinite.com/administration/log-management/search-fields/features/search-field-expressions/xpath/