XPath Tester & Evaluator
Evaluate XPath 1.0 expressions against XML documents with matched nodes inspector, counts, and cheat sheets.
Client-Side Execution & Privacy Guarantee
This utility executes 100% locally in your web browser. Your inputs, tokens, queries, and data payloads are never transmitted to any external server or backend.
XPath is the standard language for addressing parts of an XML document. The evaluator lets you write an expression, supply a document, and immediately inspect the resulting node-set, boolean, number, or string together with a count and a preview of each match.
Only XPath 1.0 is supported, matching the version still required by many SOAP stacks, XSLT 1.0 stylesheets, and legacy configuration systems. Functions from the core library (count, contains, starts-with, position, last, and the numeric and string operators) are available; XPath 2.0 and 3.0 features are not.
Location paths and axes
A location path consists of steps separated by / or //. Each step selects nodes relative to the context node using an axis (child, attribute, descendant, parent, etc.), a node test, and optional predicates. The abbreviated syntax //element is equivalent to /descendant-or-self::node()/child::element.
Predicates are evaluated for each candidate node. position() returns the position of the current node within the node-set produced by the preceding step; last() returns the size of that node-set. Attribute tests use the @ abbreviation.
Core functions and operators
The boolean functions true, false, not, and boolean convert values according to the XPath 1.0 rules. Numeric functions include number, sum, floor, ceiling, and round. String functions cover concat, starts-with, contains, substring, string-length, and translate.
The equality and relational operators (=, !=, <, >, <=, >=) perform existential comparison when either operand is a node-set: the comparison succeeds if any pair of values satisfies the relation. Arithmetic operators convert both operands to numbers first.
Context and namespaces
The context node for an absolute path is the document root. Relative paths are evaluated from the root as well in this tool so that expressions remain self-contained. Namespace prefixes appearing in the expression must be bound; unbound prefixes cause the expression to return an empty result.
The evaluator reports the string-value of each selected node, the node type, and a short path that can be copied back into a new expression. Counts are exact for the current document.
When to use this tool
- You need to verify an XPath expression before embedding it in an XSLT stylesheet or application code.
- You are debugging a SOAP or configuration document and want to extract specific elements quickly.
- You are learning XPath 1.0 and want immediate feedback on location paths and predicates.
- You must confirm how many nodes an expression selects in a particular document.
- You want to compare the results of two alternative expressions against the same XML.
How to use the XPath Tester & Evaluator
- Paste a well-formed XML document into the document pane.
- Type an XPath 1.0 expression into the expression field. Absolute paths beginning with / are recommended for clarity.
- Click Evaluate. The tool parses both the document and the expression.
- Inspect the result type, the count of selected nodes, and the list of matches with their string values.
- Use the matched-node inspector to copy a path or examine attributes and child elements.
- Modify the expression or the document and re-evaluate to iterate quickly.
- Consult the built-in cheat sheet for common axes, node tests, and function signatures when you are unsure of syntax.
Worked examples
Select all book titles
<library> <book id="1"><title>XPath Essentials</title></book> <book id="2"><title>XML Schema</title></book> </library>
Node-set (2 nodes) 1. XPath Essentials 2. XML Schema
Expression used: //book/title/text(). Count and string values are shown.
Filter by attribute
<items> <item sku="A1" price="10"/> <item sku="B2" price="25"/> <item sku="C3" price="5"/> </items>
Node-set (1 node) sku="B2" price="25"
Expression used: //item[@price > 15]. Only the matching element is returned.
Common mistakes and tips
- Remember that XPath 1.0 comparisons with node-sets are existential; //item[price = 10] succeeds if any price child equals 10, not if all do.
- Unbound namespace prefixes silently produce empty results. Declare the prefix or use local-name() if you must ignore namespaces.
- position() and last() inside a predicate refer to the node-set of the current step, not the whole document.
- The string-value of an element is the concatenation of all descendant text nodes; use text() when you need only direct text.
- Very large documents may be slow to re-parse on every keystroke; paste a reduced fragment while developing the expression.
Frequently asked questions
Why does my expression return no nodes when the element is clearly present?
The most common causes are an unbound namespace prefix or a predicate that never matches. Try local-name() or remove the predicate temporarily.
Does the evaluator support XPath 2.0 functions such as matches()?
No. Only the XPath 1.0 core function library is implemented.
How are namespaces handled?
Prefixes used in the expression must be bound to the same URIs that appear in the document. Default namespaces in the document require a prefix in the XPath.
Can I evaluate expressions that return numbers or booleans?
Yes. The result pane shows the type and the computed value for non-node-set results.
Is the document modified by evaluation?
No. Evaluation is read-only; the original XML remains unchanged.