The quick answer

Paste XML, type an XPath like //order[@status='shipped'], and see the match count plus a node list with type and value for every result, live as you type. The tester drives document.evaluate, the browser's own XPath 1.0 engine, so results match production exactly. The 13-axis cheat sheet is onboard, and your XML never uploads.

The selector language that came back from 1999

The scraping code you inherited has one line that does all the real work: //div[@class='result']/table/tr/td[3]. Nobody left a comment. The API you're integrating against returns XML, not JSON, and the integration guide says "the value is at /response/shipment[status='delayed']/eta" with no further explanation. A vendor's product feed arrives as 40 megabytes of nested elements and you need exactly three of them. All of these are XPath moments, and all of them share the same problem: you cannot write an XPath expression down confidently without running it against real data.

XPath is older than most of the people using it: the W3C published version 1.0 in November 1999, back when XML was going to be the format for everything. The prediction was wrong in general and right in specific: JSON won the APIs, but XML never left the places it had already conquered. Enterprise config files, SOAP endpoints, office document formats, RSS and Atom feeds, SVG, sitemaps, DocBook, HL7 medical records, the publishing industry's entire backbone. If you touch any of those, you touch XPath.

This tester is the missing REPL. The pane arrives with a small library sample and five one-click example expressions; paste your own XML and the same pane becomes your document's console. The worked expressions further down the page all run against one small orders file (3 orders, 5 line items): paste it from this page into the pane and reproduce every result yourself. It runs on the XPath engine already installed in your browser, so the behavior you verify here is the behavior your production code will get.

What the tester gives you

A node-set result shows two things: the count on the stat card, and a two-column list underneath, one row per node, with the node type (element name, attribute, text) in the first column and its value in the second. //order[@status='shipped'] doesn't just say "2 nodes", it shows you which two. Getting that list back matters more than it sounds: half of debugging an XPath is discovering what the expression actually selected. One honest limit: the pane is built for node-set results. An expression that computes a scalar (count(//order)) or selects nothing surfaces the panel's error note rather than a number, so a surprise there means the expression shape, not a broken page.

Evaluating an expression in four moves

  1. Put a document in

    The pane arrives with a small two-book library sample; paste your own XML over it or click one of the five example expressions. The document parses immediately: if it isn't well-formed XML, you hear about that first, before XPath enters the picture.

  2. Type the expression

    Evaluation is live. As you type, the match count updates; finish the expression and the count settles on whatever it selects.

  3. Read the results table

    One row per matched node, in document order: element name or attribute in the first column, its text or value in the second. The stat card above the table carries the count.

  4. Refine or commit

    Tighten the predicate, add a position filter, then carry the verified expression into your scraper, stylesheet, or test.

A habit worth forming: start with the broadest expression that returns anything (//order), then narrow one predicate at a time until the match count is what your business logic says it should be. The tester's instant feedback makes that a thirty-second loop. Writing the final expression in one shot, by contrast, is how //div[2]/span[contains(text(),'Total')] ends up selecting a currency label on Tuesdays and nothing at all on weekends.

The grammar, in the order it actually composes

Every location path is a sequence of steps, and every step has three parts: an axis, a node test, and any number of predicates. Written out longhand it's child::order[@status='shipped'][2], the child axis, the order node test, two predicates. Abbreviated, which is how everyone actually writes it, the child axis vanishes (order), attributes get @ (@id), parent gets .., self gets ., and descendant-or-self gets //. The abbreviations are why XPath looks like file paths with superpowers.

The node test is the coarse filter: a name like order, a wildcard like * for any element, or node() for any node at all including text and comments. Predicates are the fine filter, evaluated as boolean expressions per candidate node, left to right: [@status='shipped'] keeps matching elements, [2] keeps the second, [@status='shipped'][2] means "of the shipped ones, the second". Note that order, because [2][@status='shipped'] means "of the second one, keep it if shipped," a subtly different and usually accidental question. Stacking predicates is the feature and the trap in one syntax.

Predicates can use the full expression language, which is where XPath stops being a path language and starts being a small functional one. Arithmetic (+, -, *, div, mod; division is div because / is taken), comparisons (=, !=, <, <=, >, >=), boolean glue (and, or, not()), and the core function library: position() and last() for ordering, count() and sum() over node-sets, contains() and starts-with() and substring() and normalize-space() and translate() for text surgery, concat() for assembly, string-length() for validation. The node-test wildcards and this function set together are 90% of production XPath.

// Production XPath, annotated:

//line[@qty > 10]/@sku
  → descendant-or-self of root → any 'line' element
    with qty attribute > 10 → its sku attribute

//order[customer = 'Meridian Foods' and total > 500]/@id
  → orders for one customer whose total clears 500 → their ids

//line[not(@qty)]
  → every line element missing a qty attribute entirely: data QA

The thirteen axes, ranked by how often you'll use them

Axes are the directions a step can travel. Child is the default and covers most walking; attribute covers @; the rest exist for the moments a path needs to move sideways or upward, which is exactly what CSS selectors historically couldn't do. There are thirteen in XPath 1.0, and nobody uses them uniformly, so here they are in rough order of real-world frequency.

AxisSelectsExample
child (default)Element children of the context nodeorder/total
attribute (@)Attributes of the context nodeorder/@id
descendant-or-self (//)The node and everything below it//total anywhere
self (.)The context node itself./@status
parent (..)The node one level uptotal/.. (the owning order)
descendantEverything below, excluding selforders/descendant::total
following-siblingSiblings after the context nodecustomer/following-sibling::lines
preceding-siblingSiblings before the context nodelines/preceding-sibling::customer
ancestorAll nodes above, up to the roottotal/ancestor::order
ancestor-or-selfSame, including the context nodetotal/ancestor-or-self::*
followingEverything after in document order, excluding descendantsorder[1]/following::order
precedingEverything before in document order, excluding ancestorsorder[3]/preceding::order
namespaceNamespace nodes of the context elementrare outside XSLT
All thirteen XPath 1.0 axes. The top four cover most working expressions.

The parent and sibling axes deserve a small celebration, because they're the reason scrapers reach for XPath over CSS at all: from a price cell you can climb to its row, and from the row to the header that names the column. When the layout moves, the relationship survives, and your expression survives with it. The following and preceding axes are the ones to treat with care, because they traverse the whole document outside your subtree, so on a large file they are the slowest steps available and occasionally a correctness hazard, since 'preceding' includes nodes the human eye groups with other sections.

Six expressions against one orders file

Here is the sample document for these examples, shown in full: three orders, five line items, one shipped-status mix. Every result below is what the expressions select in this exact XML; paste it into the pane and check any of them yourself.

<orders>
  <order id="A-1001" status="shipped">
    <customer>Meridian Foods</customer>
    <lines>
      <line sku="SKU-91" qty="12" unit="41.50"/>
      <line sku="SKU-33" qty="4" unit="129.00"/>
    </lines>
    <total>1014.00</total>
  </order>
  <order id="A-1002" status="open">
    <customer>Halcyon Print</customer>
    <lines>
      <line sku="SKU-91" qty="2" unit="41.50"/>
    </lines>
    <total>83.00</total>
  </order>
  <order id="A-1003" status="shipped">
    <customer>Meridian Foods</customer>
    <lines>
      <line sku="SKU-17" qty="30" unit="8.25"/>
    </lines>
    <total>247.50</total>
  </order>
</orders>
Worked example: counting and filtering

Input

//order[@status='shipped']/@id
//line[@qty > 10]/@sku

Output

//order[@status='shipped']/@id → 2 nodes: A-1001, A-1003

//line[@qty > 10]/@sku → 2 nodes: SKU-91 (qty 12), SKU-17 (qty 30)

Both are attribute results: the results table lists them with their values, and the stat card reads 2 in each case. @qty > 10 is XPath's numeric comparison: the attribute's string value converts to a number first, the same number() conversion the spec defines.
Worked example: aggregation and compound predicates

Input

//order[customer = 'Meridian Foods' and total > 500]/@id
//line[position() = 2]/@sku

Output

//order[customer = 'Meridian Foods' and total > 500]/@id → 1 node: A-1001 only
  (A-1003 is Meridian Foods but totals 247.50)

//line[position() = 2]/@sku → 1 node: SKU-33
  (only order A-1001 has a second line element; position() counts siblings, not document-wide)

Aggregation arithmetic stays in the language: the two shipped totals are 1014.00 and 247.50, so sum() over them is 1261.50, a figure you can check by hand even though the pane is built for node-set results.
Worked example: the case-insensitive contains() workaround

Input

//customer[contains(., 'meridian')]
//customer[contains(translate(., 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz'), 'meridian')]

Output

First expression selects nothing: contains() is case-sensitive in XPath 1.0, and the element's text is 'Meridian Foods' with a capital M.

Second expression → 1 node: <customer>Meridian Foods</customer>

The translate() call folds the element text to lowercase before the comparison. This is the canonical XPath 1.0 idiom, and it works on attribute values identically.

The last worked example is the one to memorize, because case-sensitive contains() bites everyone exactly once. The fold-the-case-with-translate() trick, mapping A–Z down to a–z on both sides of the comparison, predates Google and will outlive us all, at least until browsers ship an XPath newer than 1.0, a decision they have now declined for over two decades. Until then, translate(name, 'ABC…', 'abc…') is the portable answer, and example three above shows it working.

Namespace pain and other well-known traps

  • Namespaces, the big one. If the root declares xmlns="http://www.w3.org/1999/xhtml" (or any default namespace), every unprefixed element name in your XPath matches nothing, because in XPath 1.0 an unprefixed name matches only elements in no namespace. The fix in real code is a namespace resolver mapping a prefix of your choice to that URI, then x:html/x:body. Honest limit: this pane evaluates with no resolver, so prefixed names cannot resolve here (the browser rejects them with an unresolvable-namespace error); test namespaced documents in your own tooling.
  • Text nodes versus string values. /order/customer returns the customer element; /order/customer/text() returns its text node. For comparisons it rarely matters, because string() of an element includes descendant text, but node-identity and count() care a lot, and text() breaks silently when a value is split across multiple text nodes by markup.
  • The double-slash performance tax. // scans the entire subtree from the document root every time it appears. On a 40 MB product feed, //sku inside a loop is the difference between seconds and a coffee break. Anchor your paths (orders/order/lines) whenever the structure is stable enough to describe.
  • Position is per-axis, per-step. line[2] means the second line child among its siblings, not the second match document-wide. To get the second match overall, filter the outer step: (//line)[2], parentheses first, then the position predicate. Those parentheses are load-bearing.
  • Numbers are IEEE double precision. Attribute comparisons like @qty > 10 do exact floating-point math: quantities stored as 41.50 are fine, but penny arithmetic on decimal values can wobble in the usual 0.1-plus-0.2 way. Don't build a billing engine out of XPath predicates.
  • Comments are nodes. The node() wildcard and the comment() node test can both select XML comments, and a naive text extraction can accidentally include a commented-out block that a human "deleted" fifteen years ago. Ask for element names explicitly when it matters.
  • CDATA is just text. What the document author wrapped in <![CDATA[...]]> arrives as an ordinary text node as far as XPath is concerned: invisible in the syntax, occasionally surprising when a "different-looking" value compares equal to a plain-text one.

Who still lives in XPath

Integration engineers, mostly: people whose week is a parade of other people's formats. Backend developers paste a live API response straight into the pane when the integration guide says "the value is at /response/shipment[status='delayed']/eta" and nothing else. The freight system speaks XML, the publisher's CMS speaks XML, and the government data portal absolutely speaks XML, frequently XML from 2003 with a schema PDF to match. When the requirement is "pull fields X, Y, and Z out of this payload," the expression work happens here first, against a real sample, until the match count is boring.

Scrapers form the second camp, split between XPath and CSS partisans in a way that generates entertaining team arguments. XPath earns its following for the reasons above: upward traversal, attribute selection, functions, and compound predicates that CSS only answers with the newer :has() and attribute operators. Test automation leans the same way: Selenium and Playwright both accept XPath locators, and a locator verified in a tester before it's committed is a locator that doesn't fail at 2 a.m. in CI.

The third camp is quieter: XSLT maintainers (stylesheets are XPath with a rendering engine attached), technical writers in DocBook territory, anyone doing batch transformations with tools like xsltproc, and data people sanity-checking sitemap XML before search-console work. Their expressions are fewer and stranger, and they do their namespace work in their own tooling; this pane, as above, wires no resolver.

XPath versus CSS selectors

For scraping HTML, the eternal question: XPath or CSS? Both work. They differ in ways that matter once you leave the happy path.

CapabilityXPath 1.0CSS selectors
Select by id/class/attributeYes: [@id='x'], [@class~='x']Yes: #x, .x, [attr]
Text content matchingYes: contains(., 'x'), starts-with()No (attribute values only)
Move upward (parent, ancestor)Yes: .., ancestor::Only via :has() (recent addition)
Select attributes as resultsYes: /@sku returns the attribute itselfNo: matching elements only
Arithmetic and aggregationYes: sum(), count(), comparisonsNo
Position among all matchesYes: (//line)[3]Yes: :nth-of-type, with different semantics
Readability for simple descendanceVerboseClearly better
Engine availabilitydocument.evaluate in all modern browsersquerySelector, generally faster
Choosing between the two selector languages for scraping and automation.

The practical split we see: CSS when the path is short, downward, and structural (article > h2, #results .row), because it reads cleanly and browser engines are tuned hard for it. XPath the moment you need text matching, a climb to a parent, attribute values as the result, or a compound condition across two attributes. The tester here plus the browser console's $x() make it cheap to prototype in XPath and only commit what survives contact with the page. And when the data is JSON rather than markup, neither applies: that's JSON Path Tester territory.

It runs on the engine your browser already ships

There is no XPath implementation on this page to trust, because the browser brought one. The tester calls document.evaluate, the standard DOM API present in every modern browser since the mid-2000s, hands it your expression and your document, and renders whatever XPathResult comes back. What you test is not a reimplementation that approximates the spec; it is the same engine your scraper's browser session, your XSLT processor's cousin, and your production code will exercise. When a result surprises you here, it would surprise you in production identically.

The document you paste never crosses the network. Parsing, evaluation, listing: all local, all in-tab, gone when the tab closes, so your API payloads and vendor feeds run with Wi-Fi off if you like. That is not just a privacy posture; it is what makes an offline XPath REPL possible on a train or inside a locked-down environment. Load the page once and the network panel stays quiet thereafter; verify it yourself if you like.

Frequently asked questions

Which XPath version does this tester use?

XPath 1.0: the version web browsers implement through document.evaluate. That means full support for location paths, all thirteen axes, predicates, and the core function library, but none of the XPath 2.0/3.1 additions like ends-with(), lower-case(), for-expressions, or regular-expression matching. For scraping and config work, 1.0 remains the dialect that actually runs everywhere.

What is the difference between a single slash and a double slash?

A single slash steps through the hierarchy strictly: /orders/order/total walks the exact path from the root. A double slash is shorthand for descendant-or-self::node()/, and it selects at any depth below the context node, so //total finds every total element no matter how deeply nested. The single slash is precise and fast; the double slash is convenient and, on large documents, measurably slower.

How do I make contains() case-insensitive?

XPath 1.0 has no lower-case() function, so the standard workaround folds the case yourself with translate(): contains(translate(., 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz'), 'searchterm'). Ugly, reliable, and the answer you will find in every Stack Overflow thread on the subject. The worked example below ships the pattern ready to paste.

Why does my expression match nothing on an XHTML page?

Namespaces. XHTML documents place every element in the http://www.w3.org/1999/xhtml namespace, and in XPath 1.0 an unprefixed name matches only elements in no namespace at all, so /html finds nothing. The fix in real code is a namespace resolver that maps your chosen prefix to the XHTML URI, then expressions like x:html/body. This tester evaluates with no resolver wired, so it cannot run those prefixed expressions itself; it is still the fastest way to see the empty match that tells you namespaces are the problem.

Is the first node in a predicate [1] or [0]?

One. XPath predicates are one-indexed, unlike nearly every programming language you use. //line[1] is the first line element among its siblings, //line[last()] is the final one, and //line[position() > 1] skips the first. Half of all beginner XPath bugs are an off-by-one from this single fact.

How is XPath different from JSONPath?

Same idea, different data model. XPath walks XML's tree of elements, attributes, and text nodes with axes and a function library; JSONPath walks JSON's objects and arrays with a dot-and-bracket syntax. The mental model of 'describe the path, get the nodes' carries over, but the syntaxes share almost nothing. If your data is JSON, use the JSON Path Tester instead of forcing XPath onto it.

Is my XML sent to a server?

No. The expression runs against your document using the browser's own XPath engine, entirely inside the tab. Nothing is transmitted, stored, or logged, which is the point of building on document.evaluate rather than shipping the document off to a service.

Sources and further reading

Sources and further reading

We cite primary sources (standards bodies, government agencies, official documentation) wherever they exist so you can verify every number on this page yourself.