⚡deftools.io Developer Tools

🔍 XPath Tester

Test XPath expressions against XML and see matching nodes highlighted with counts and previews

0 chars
XPath Quick Reference
Node selection
//book — all <book> elements anywhere
/bookstore/book — absolute path
//book[1] — first <book>
//book[last()] — last <book>
//* — all elements
//book/title/text() — text nodes only
Predicates & axes
[@category='fiction'] — attribute filter
[price>10] — numeric filter
[contains(title,'Hobbit')] — text match
//author/.. — parent of <author>
//book/ancestor::* — all ancestors
count(//book) — count nodes

About this tool

XPath (XML Path Language) is a query language for selecting nodes from an XML document. Think of it as "SQL for XML" — you write path expressions to navigate the tree structure and extract elements, attributes, or text that match criteria.

Example: given a <bookstore> with multiple <book> elements, the expression //book[@category='fiction']/title selects only the title elements of fiction books. The expression sum(//price) returns the total of all prices as a number.

Paste your XML and an XPath expression, then press Run (or Ctrl/Cmd+Enter) to see matching nodes with previews and type labels. The tool handles element, attribute, text, comment, and CDATA nodes.

FAQ

What XPath version does this use? ›

The browser's built-in XPath engine (DOM Level 3 XPath) supports XPath 1.0 with a few extensions. Functions like <code>lower-case()</code> and <code>matches()</code> (XPath 2.0) are not available — use <code>translate()</code> for case-insensitive matching instead.

Why does my XPath return no results even though the XML looks fine? ›

The most common cause is namespace prefixes. If your XML uses <code>xmlns="..."</code>, you need to register the namespace. The tool maps common prefixes (xsl, svg, atom, soap, etc.) automatically, but custom ones require a namespace resolver — for simple testing, try the local-name() workaround: <code>//*[local-name()="book"]</code>.

Can I test XPath expressions that return numbers or strings? ›

Yes. Expressions like <code>count(//book)</code>, <code>sum(//price)</code>, or <code>string(//title[1])</code> return numeric, string, or boolean results. The tool detects the result type and displays it accordingly.

How is this different from JSONPath? ›

XPath works on XML documents and supports rich predicates, axes, and functions. JSONPath works on JSON data with dot/bracket notation. Use XPath for XML, SOAP, HTML, RSS/Atom feeds; use JSONPath for REST API responses and JSON config files.

More developer tools

Copied!