Skip to content
DevToolKit

Online XPath Tester

Test and debug XPath expressions against XML documents with real-time evaluation, namespace discovery, match highlighting, and multiple result views. Free, private, browser-based.

XML Input
XPath Quick Reference
Was this tool helpful?

How to Use

The Online XPath Tester is an interactive workbench for writing, testing, and debugging XPath expressions against XML documents. It uses the browser's native XPath 1.0 engine, which means your XML data never leaves your device.

How to use this tool

  1. Paste XML: Enter or paste your XML document into the left panel. The tool validates the document in real-time and reports parsing errors with line numbers.
  2. Write an XPath expression: Type your query in the XPath Expression field. Results update instantly as you type. Use the Quick Reference panel for syntax reminders.
  3. Review results: Matched nodes appear in three views: Nodes shows each match as an expandable card with type, path, attributes, and serialized XML; Text extracts plain text values; Table renders element children as columns.
  4. Handle namespaces: The tool auto-discovers all namespace declarations in your XML and registers them. Edit prefix-to-URI mappings in the collapsible Namespaces panel if needed.
  5. Load samples: Click "Load Sample" to try pre-built examples: a bookstore catalog, a SOAP envelope with namespaces, or an RSS feed.
  6. Beautify XML: Click "Beautify" to auto-indent your XML for easier reading before querying.

About This Tool

What Is XPath?

XPath (XML Path Language) is a W3C standard query language for selecting nodes from XML documents. First published as a recommendation in November 1999 alongside XSLT 1.0, XPath uses path expressions to navigate through the hierarchical structure of an XML document. The language treats an XML document as a tree of nodes -- element nodes, attribute nodes, text nodes, namespace nodes, processing instruction nodes, comment nodes, and the root document node. Every node in the tree can be addressed by an XPath expression that describes its location relative to the root or to other nodes.

XPath 1.0 in the Browser

This tool uses the browser's native document.evaluate() API, which implements XPath 1.0. Despite being the first version of the specification, XPath 1.0 covers the vast majority of practical use cases: location paths with axes (child, descendant, parent, ancestor, following-sibling, preceding-sibling), predicates for filtering ([@attr='value'], [position()=1], [last()]), built-in functions (contains(), starts-with(), string-length(), count(), sum()), and four data types (node-set, string, number, boolean). The native implementation is fast and memory-efficient because it operates directly on the browser's DOM tree without requiring a third-party library.

Axes and Predicates

XPath axes define the relationship between the context node and the nodes to select. The child:: axis (the default when using /) selects direct children. The descendant:: axis (abbreviated //) selects all descendants at any depth. The ancestor:: axis traverses upward, while following-sibling:: and preceding-sibling:: navigate horizontally within the same parent. Predicates in square brackets filter the selected node set: //book[price > 20] selects books with a price child whose numeric value exceeds 20, and //item[contains(@class, 'active')] matches elements whose class attribute contains the substring "active".

Namespace Handling

XML namespaces are the most common source of XPath debugging frustration. When an XML document declares a default namespace (xmlns="http://..."), all unprefixed elements belong to that namespace -- but XPath 1.0 treats unprefixed names in expressions as belonging to no namespace. This means //element will match zero nodes in a namespaced document. The solution is to register a prefix for the namespace and use it in queries: if the namespace is registered as ns, write //ns:element. This tool auto-discovers all namespace declarations and registers them, so you can use the prefixes directly in your XPath expressions. Related tools like the XML Formatter and XML to JSON Converter can help you inspect namespace structure.

Why Use This Tool

Debugging XSLT Transformations

XSLT stylesheets rely entirely on XPath expressions to select template match patterns and extract values. When a transformation produces unexpected output, the first step is isolating the XPath query that fails. Paste the source XML into this tool, test individual xsl:for-each select expressions, and verify that xsl:value-of expressions return the expected text. This iterative testing approach is faster than repeatedly running the full transformation.

Web Scraping Selector Validation

XPath is supported by major scraping frameworks including Scrapy (Python), lxml, Selenium, and Puppeteer. Testing selectors against sample XML or XHTML before embedding them in scraper code eliminates a common class of bugs. Combined with the JSON Formatter for inspecting API responses and the Regex Tester for text extraction, this tool completes a comprehensive data extraction workflow.

SOAP and Enterprise XML Inspection

Enterprise integrations frequently involve SOAP web services, SAML assertions, HL7 CDA clinical documents, and XBRL financial reports -- all heavily namespaced XML formats. This tool's automatic namespace discovery and registration makes it straightforward to query these complex documents without manually configuring namespace resolvers. The XML Validator can verify document well-formedness before querying, and the HTML Formatter helps with XHTML content inspection.

100% Private Processing

All XML parsing and XPath evaluation happens entirely in your browser using the native DOMParser and document.evaluate() APIs. Your data never leaves your device -- there are no network requests, no server-side processing, and no data retention. This makes it safe for testing against confidential configuration files, SOAP messages containing authentication tokens, or any XML document with sensitive data.

FAQ

Which version of XPath does this tool support?
This tool uses the browser's native document.evaluate() which implements XPath 1.0. This covers the most common queries including element selection, attribute matching, text predicates, axes (ancestor, descendant, following-sibling), and position functions.
How does namespace handling work?
The tool automatically discovers all namespace declarations in your XML document and registers them for use in XPath queries. You can also manually add or edit namespace prefix-to-URI mappings in the Namespaces panel.
Can I test XPath expressions for web scraping?
Yes. While this tool works with XML, many XPath concepts apply to HTML parsing in web scraping tools like Scrapy, lxml, and Puppeteer. Test your expressions here against well-formed XML or XHTML documents before using them in your scraper.
Why does my XPath return no results?
Common causes: namespace-qualified elements require a prefix in XPath (e.g., //ns:element instead of //element), case sensitivity matters in XPath, and the expression might target attributes instead of elements. Check the auto-discovered namespaces panel and adjust your query.
Is my XML data processed on a server?
No. All XML parsing and XPath evaluation happens entirely in your browser using the native DOMParser and document.evaluate() APIs. Your data never leaves your device.