XPath Tester

Test XPath expressions online against your XML and see every matching node, with its path and line. It runs entirely in your browser, so your XML is never uploaded.

The XPath tester runs entirely in your browser and needs JavaScript. Everything else on this page works without it. Alternatives: xmllint --xpath on the command line, or the lxml library in Python.

Try:

Paste XML, drop a file or load the example. Files are read in your browser: nothing is uploaded.

Result

XPath 1.0, evaluated by your browser. Show in input selects a match in your XML.

The nodes or the value your expression selects will appear here.

Did this tool help? Support XMLNest

How do I test an XPath expression?

Paste your XML on the left, or drop a file on it. Type an expression in the XPath field and press Enter or Evaluate. Each matching node appears with its kind, a short path such as /catalog/book[2]/title, its line and its content. Show in input selects that node in your XML. A function such as count() gives a number instead, and the result shows it. Copy and Download give the result as plain text. Load example opens a book catalog you can try straight away.

Why does my expression return nothing?

Nine times out of ten, a namespace. When the root element has xmlns="…", every element without a prefix belongs to that default namespace, and a plain //book no longer matches it. This tester gives the default namespace a prefix, d unless you choose another one under Namespaces, and suggests the corrected expression when it spots the problem. Other usual causes: a typo in a name, since XML is case-sensitive, or a missing @ before an attribute.

Expression examples to try

//book/title lists every title. //book[@lang='en'] keeps the books whose lang attribute is en. count(//book) counts them, and sum(//price) adds up prices. //title[contains(., 'Dark')] finds titles that contain a word, and //book[last()] takes the last book. To select an attribute itself, write //book/@id. The text() test returns text nodes, while string() returns the full text of an element.

Which XPath version does this evaluator support?

XPath 1.0, the version built into every browser, with its 27 functions. XPath 2.0 and 3.1 are not supported, so lower-case(), matches() or if … then … else give a clear message, often with a 1.0 alternative. The same expressions work in an XSLT 1.0 stylesheet: try them in the XSLT tester. If your XML has a syntax error, the tester shows its line first, as the XML validator does.

Does this tool upload my XML?

No. The expression is evaluated in this browser tab, and the security rules of this page block network requests. Nothing is saved: close the tab and your XML is gone. To make a long single-line file readable first, use the XML formatter.

Questions

Why does //book find nothing when my XML has book elements?

Your XML probably has a default namespace, written xmlns="…" on the root. In XPath 1.0, a name without a prefix only matches elements in no namespace. This tester gives the default namespace a prefix, d by default, so write //d:book.

Can I use XPath 2.0 or 3.1 functions?

No. Browsers ship XPath 1.0, and this tester uses the browser engine. Functions such as lower-case() or matches() return a clear message, often with an XPath 1.0 way to get the same result.

What is the difference between text() and string()?

text() selects the text nodes directly inside an element, so you get nodes back. string() returns the text of the whole element, children included, as one value.

How do I count or filter nodes?

count(//item) gives a number. //item[contains(@name, 'pro')] keeps items whose name contains pro. //item[position() <= 3] keeps the first three, and //item[last()] the last one.

How large can my XML be?

Up to 10 MB. The list shows the first 500 matches, and Copy or Download give all of them as plain text.

Is my XML sent anywhere?

No. The expression runs in this browser tab, and the page is not allowed to send network requests. Close the tab and your XML is gone.