XPath Tester

Evaluate an XPath expression against pasted XML.

Open tool

Overview

Paste XML and an XPath expression to see which nodes match - element names, attribute values, or text content. Supports XPath 1.0 axes (child, descendant, attribute, parent, following-sibling), predicates with [position()], function calls (contains(), starts-with(), text()), and namespaces.

It's for developers parsing XML configs, scraping HTML (with HTML-aware namespace handling), or testing selectors before wiring them into an ETL pipeline. Reach for it when a SAX parser isn't matching what you expect, when reverse-engineering an unknown XML format, or when piecing together a CDATA-laden response from a SOAP service.

How it works

XPath 1.0 is the W3C specification that defines the path-like syntax used to address parts of an XML document. The tester parses your expression and evaluates it against the parsed input tree, returning a node set, string, number, or boolean depending on the expression type.

Common XPath axes (/, //, .., @), predicates ([1], [@class='x']), and functions (text(), contains(), starts-with(), count()) are supported. Namespace-bound elements need their namespaces declared explicitly when querying; HTML inputs without namespaces work without setup.

Examples

  • Match every element by name:
    XPath: //book/title
    Returns: all <title> elements that are direct children of <book>
    
  • Predicate with attribute filter:
    XPath: //a[@class='external']/@href
    Returns: the href attributes of <a> tags with class="external"
    
  • Containing text:
    XPath: //p[contains(text(), 'error')]
    
  • Indexing (XPath is 1-based):
    XPath: //li[1]   -> first <li> in each parent
    XPath: (//li)[1] -> first <li> in the whole document
    

FAQ

Is XPath 1.0 or 2.0/3.0 supported?

The tester targets XPath 1.0, which is the version most XML libraries (libxml2, .NET's XPathNavigator, browser evaluate) support without extensions. XPath 2.0+ adds sequences and a richer type system but isn't universal.

Can I use XPath on HTML?

Yes, with the caveat that HTML isn't strictly XML. Most HTML parsers (HTML5 lib, browser DOM) accept XPath against the parsed tree. Mismatched tags and entities are tolerated.

Why doesn't my namespaced query match?

XPath 1.0 requires explicit namespace prefixes. For an XML document with xmlns="http://example.com", you can't use unqualified element names - register the namespace and reference it via a prefix.

Should I use XPath or CSS selectors for HTML?

CSS selectors are usually simpler. XPath is more powerful (parent axis, complex predicates, text node matching) but verbose. Use whichever fits the use case.

Try XPath Tester

An unhandled error has occurred. Reload ×