---
title: "XPath2 Extractor"
description: "Configure the JMeter XPath2 Extractor post-processors: properties, defaults, and practical usage notes for building reliable load tests."
url: https://docs.jmeter.ai/components/xpath2-extractor/
lastUpdated: 2026-10-01
source: docs.jmeter.ai
---

# XPath2 Extractor

*Part of the **Post-Processors** category. Also documented in context in the [full Component Reference](/user-manual/component-reference/#xpath2-extractor).*

![XPath2 Extractor](/images/screenshots/xpath2_extractor.png)

This test element allows the user to extract value(s) from structured response - XML or (X)HTML -
using XPath2 query language.

| Name | Required | Description |
| --- | --- | --- |
| Name | No | Descriptive name for this element that is shown in the tree. |
| Apply to: | Yes | This is for use with samplers that can generate sub-samples,         e.g. HTTP Sampler with embedded resources, Mail Reader or samples generated by the Transaction Controller.          - `Main sample only` - only applies to the main sample - `Sub-samples only` - only applies to the sub-samples - `Main sample and sub-samples` - applies to both. - `JMeter Variable Name to use` - extraction is to be applied to the contents of the named variable         XPath matching is applied to all qualifying samples in turn, and all the matching results will be returned. |
| Return entire XPath fragment instead of text content | Yes | If selected, the fragment will be returned rather than the text content.     For example `//title` would return “`&lt;title&gt;Apache JMeter&lt;/title&gt;`” rather than “`Apache JMeter`”.     In this case, `//title/text()` would return “`Apache JMeter`”. |
| Name of created variable | Yes | The name of the JMeter variable in which to store the result. |
| XPath Query | Yes | Element query in XPath 2.0 language. Can return more than one match. |
| Match No. (0 for Random) | No | If the XPath Path query leads to many results, you can choose which one(s) to extract as Variables:      - `0`: means random (default value) - `-1` means extract all results, they will be named as `_&lt;variable name&gt;__N` (where `N` goes from 1 to Number of results) - `X`: means extract the Xth result. If this Xth is greater than number of matches, then nothing is returned. Default value will be used |
| Default Value | yes | Default value returned when no match found.     It is also returned if the node has no value and the fragment option is not selected. |
| Namespaces aliases list | No | List of namespaces aliases you want to use to parse the document, one line per declaration.     You must specify them as follow: `prefix=namespace`. This implementation makes it easier to     use namespaces than with the old XPathExtractor version. |

To allow for use in a [ForEach Controller](/components/foreach-controller/), it works exactly the same as the above XPath Extractor

XPath2 Extractor provides some interestings tools such as an improved syntax and much more functions than in its first version.

Here are some exemples:

**`abs(/book/page[2])`**
: extracts 2nd absolute value of the page from a book

**`avg(/librarie/book/page)`**
: extracts the average number of page from all the books in the libraries

**`compare(/book[1]/page[2],/book[2]/page[2])`**
: return Integer value equal 0 to if the 2nd page of the first book is equal to the 2nd page of the 2nd book, else return -1.

To see more information about these functions, please check [xPath2 functions](http://saxon.sourceforge.net/saxon7.9.1/functions.html)

## Related

- [Correlation & Dynamic Values](/topics/correlation-dynamic-values/)
- [Regex Extractor Builder](/tools/regex-tester/)
- [Full Component Reference](/user-manual/component-reference/)
- [Functions and Variables](/user-manual/functions/)
