XML XPath value extractor

Test an XPath on your file before using it in code or in a scraping or import tool.

Loading the tool…

Processing and privacy: The result is calculated inside your browser and your data is not sent to any server.

How to use it

  1. Enter xml text and xpath expression.
  2. The result appears straight away and updates as you edit.
  3. Copy the result, or copy a link that keeps the same values to share it.

How it is calculated

A subset of XPath 1.0: / for children and // for all descendants, an element name or *, predicates [n], [last()], [@attr], [@attr="v"] and [child="v"], and at the end @attr, @* or text(). An element value is its full text with spaces collapsed. [n] applies per parent, as in XPath.

Example

Inputs: XPath expression = /catalog/book/title. Result: Matching values: مقدمة ابن خلدون Arabian Sands; Matches: 2.

<?xml version="1.0" encoding="UTF-8"?>
<catalog>
  <book id="1" lang="ar">
    <title>مقدمة ابن خلدون</title>
    <author>ابن خلدون</author>
    <price>45</price>
  </book>
  <book id="2" lang="en">
    <title>Arabian Sands</title>
    <author>Wilfred Thesiger</author>
    <price>60</price>
  </book>
</catalog>
مقدمة ابن خلدون
Arabian Sands

Limits and caveats

  • Functions such as contains() and count(), axes such as parent:: and and/or operators are not supported.
  • Prefixes such as ns:tag match literally, without namespace binding.
  • text() skips whitespace-only text nodes.

Questions about this tool

What is the difference between / and //?

A single slash steps to direct children only, a double slash searches every level below the current point.

Why does //*[2] return several results?

Because [2] means the second child within each parent separately, so every parent with two or more children contributes one, as standard XPath does.

How do I read an attribute value?

End the path with @ and the attribute name, such as //book/@id for every id, or @* for all attributes.