XPath Basics: Paths, Predicates, and Axes
XPath navigates an XML document as a tree of nodes. A path like /root/item selects the item children of root directly beneath the document root; //item (with a double slash) selects item elements anywhere in the document, at any depth. Square-bracket predicates filter matches, like //item[@id="42"] (an item with a specific attribute) or //item[1] (the first item among its siblings). Axes like @ (attribute), text() (a text node), and . (the current node) let you select something other than an element itself.
Reading Typed Results
Each match is labeled with its type, since XPath expressions can return fundamentally different kinds of results depending on how they're written. Element matches show the full tag with its attributes and text content. Attribute matches (from an @attr selector) show the attribute name and value directly. Text matches show just the text node's content. String, number, and boolean matches appear when the expression itself computes a value, like count(//item) (a number) or //item[1]/@id = "1" (a boolean).
Common XPath Patterns
A few patterns cover most real-world queries: //item[@type="book"] selects elements by attribute value, //item[3] or //item[last()] selects by position, //item[contains(text(), "Widget")] selects by partial text content, and //item/@id selects just the id attribute values across every matching item. Combining a path with one or more predicates is how nearly every practical XPath query is built.
Honest Scope: XPath 1.0, Not 2.0/3.0
This tool evaluates XPath 1.0 expressions. It does not support XPath 2.0/3.0-only features like the matches() regex function, sequence types, if/then/else expressions, or the for expression, capabilities some other online XPath testers advertise. XPath 1.0 covers the vast majority of real-world use cases (web scraping, test automation locators, XML data extraction) and is what most XML tooling and older browser/library implementations actually support, but if your expression relies on a 2.0-only function, it won't evaluate here.
Debugging an Expression That Matches Nothing
A zero-match result almost always means one of a few things: a typo in an element or attribute name (XPath is case-sensitive), a missing leading // when you meant "anywhere in the document" instead of a specific absolute path, an XML namespace on the elements that isn't accounted for in the expression, or a predicate condition that doesn't actually match the data's real structure. Start with a broader path like //* to see what's actually in the document, then narrow down predicate by predicate. As an xpath query tool built to test xpath expression syntax, it works as xpath online, an xml xpath query tester, an xpath 1.0 tester, an xpath expression checker, an xpath selector tester, and an xpath validator before you drop the expression into real code.