Skip to main content

XPath tester

Paste an XML document and an XPath expression, run the query, and inspect the nodes or values that match your expression.

  • Clipboard
  • Export

Embed this widget

Customize the result, check the live preview, then copy the code.

Preview

Embed code type

Code to copy

Responsive and automatically resized by Bethemesh.

Expression

Was this tool useful?

How does this tool work?

Evaluate XPath against XML and inspect selected values, counts or conditions. The tester uses your browser’s XPath 1.0 engine and keeps both inputs on your device. It helps explore a small XML export or prepare a selector. Output is text: selecting elements returns their content rather than their complete markup. A query that works here may still need adaptation to the context of the application that will use it.

Input must be well-formed XML. The shared parser rejects DOCTYPE declarations. Evaluation starts at the complete document: /root/item starts at the root and //item searches descendants throughout the document. XPath positions start at 1, so /root/item[1] selects the first item, unlike a zero-based JSON array index. Predicates such as [@id='a'] filter by attributes.

A node selection produces one textContent value per node, separated by a line break. Nested elements contribute text but their tags are not included. Scalars appear directly: count(...) yields a number, string(...) text and boolean(...) true or false. Selecting no nodes produces empty text, which does not necessarily mean the expression is invalid.

This tester has no configured namespace prefix resolver. Expression prefixes are therefore not automatically linked to document prefixes. A default namespace can also make an unprefixed name select nothing. Use explicit local-name() and namespace-uri() predicates where necessary. XPath 2.0 and 3.1 functions, sequences and advanced types are unsupported.

How to use this tool

  1. Provide XML and a query

    Paste the complete document and enter XPath 1.0. Both fields affect the result; editing either requires another evaluation.

  2. Evaluate and interpret

    Run the query and check the expected result type. Nodes become text without tags; functions can return numbers or booleans.

  3. Export the values

    Copy or download the text after checking spaces and line breaks. To retain XML elements, use extraction that explicitly serializes nodes.

Use cases

Inspect an XML export

Select repeated element values before an import. Output line breaks do not make the text a structured CSV file.

Count a collection

Use count(/root/item) for a number instead of a list. Distinguish zero matching elements from an expression returning an empty string.

Check a predicate

Test an attribute filter with known elements, including both a match and an item that should be excluded.

Examples

Select the second element

XPath positions start at 1, so [2] selects B. The output is its text rather than the item tag.

Input

<root><item>A</item><item>B</item></root>
/root/item[2]

Result

B

Count the elements

count returns 2 regardless of text length. The interface displays this scalar result as text.

Input

<root><item>A</item><item>B</item></root>
count(/root/item)

Result

2

Tips and best practices

  • Prefer a precise absolute path to // when possible: a global search may select same-named elements in unrelated sections.
  • For namespaces, combine local-name() with namespace-uri() to distinguish identically named elements from different vocabularies.
  • For an attribute, try /root/item/@id: it returns the attribute value rather than the item element’s child text.

Sources and references

Frequently asked questions

Why does /root/item find nothing?

Check structure, letter case and namespaces. A default namespace changes element names even when there is no visible prefix.

Can I use XPath 3.1?

No. This uses the browser’s XPath 1.0 engine. Later functions or sequences may cause an error.

Why are tags missing from the result?

The tester extracts textContent from each selected node. It does not serialize elements as XML or provide a reversible conversion.

How do I distinguish false from no nodes?

boolean(...) displays false, whereas an empty node selection produces empty output. Use a scalar function when that distinction matters.

Related tools

Tools similar or complementary to this one.

Similar tools

Format, minify, and validate an XML document directly in your browser.

DevelopmentUse this tool

Query JSON data with a simple JSONPath expression.

DevelopmentUse this tool