XPath Tester
FV-36Paste an XML document, a line with only =====, and an XPath expression. You get the matching nodes, or the number, text or true/false the expression returns.
Runs in your browser. Nothing is uploaded.
XML, then a line with only =====, then the XPath expression
Result
How to use it
- Paste the XML, then a line with only =====, then one XPath expression such as //book[price > 15]/title.
- Choose to see matching nodes as XML or as their text content.
- Click Evaluate.
- Read the count and the list of matches, or the single value.
XPath 1.0 in your browser
The expression is evaluated by the XPath 1.0 engine in your browser through document.evaluate. That covers paths, predicates, axes, and the standard functions such as count(), contains(), string-length() and sum(). XPath 2.0 and later features, such as matches(), for expressions and sequences, are not available. A path returns a list of nodes; count(//book) returns a number; contains(//title, 'SQL') returns true or false.
Namespaces and limits
Prefixes used in the expression are looked up from the namespace declarations on the root element. XPath 1.0 cannot match an element in a default namespace (xmlns="...") by its plain name, so use //*[local-name()="item"] for those documents. Up to 1000 matching nodes are listed. Attributes are shown as name="value", and text nodes as their text.
Error messages and what to do
| Message | What it means | Fix |
|---|---|---|
Nothing below =====. Put the XPath expression there. | The separator is present but no expression follows it. | Write the XPath expression below the line with =====. |
The XML above ===== is empty. | There is no XML before the separator. | Paste the XML above the separator line. |
Questions people ask
How do I test an XPath expression online?
Paste the XML and the expression into the box, separated by a line with only =====, and click Evaluate. Matching nodes are listed with their type.
Why does my XPath find nothing in XML with xmlns?
XPath 1.0 treats a name without a prefix as having no namespace. If the document declares a default namespace, use //*[local-name()="item"] or an expression with a prefix declared on the root.
Which XPath version does this use?
XPath 1.0, the version built into browsers. Functions added in XPath 2.0 and 3.0 are not supported and give an error. Check for matches(), lower-case(), or a for expression, which are the usual signs of a newer version.
How do I get an attribute value with XPath?
Select the attribute, for example //book/@id. Each match is listed as id="b1". Use Text content to see only the values. An expression such as string(//book[1]/@id) returns just the one value as a string.
Can XPath return a number or a boolean?
Yes. count(//book) returns a number, sum(//price) adds the values, and //book[1]/price > 10 returns true or false. These are shown as one value instead of a node list.
What does the text content option show?
For each matched node, its string value: the text of an element and all its children joined together, the value of an attribute, or the text of a text node.
About this tool
Uses the XPath 1.0 engine built into your browser, so functions from XPath 2.0 and later, such as matches() or a for expression, are not available. The result is a list of nodes (elements, attributes, text, comments), or a single number, string or true/false when the expression returns one. Up to 1000 nodes are listed. Prefixes in the expression are resolved from the namespace declarations on the root element. Elements in a default namespace (xmlns="...") cannot be reached by plain names in XPath 1.0; use //*[local-name()="item"] instead. The XML must be well-formed. Nothing is loaded from outside the page.