PrettifyPrettify

XPath Tester and Playground

Test an XPath expression against your own XML and see what it selects. Prettify runs the query with the XPath 1.0 engine in your browser, and it works on RSS and Atom feeds too. The box on this page loads and formats your XML; the XPath panel in the editor runs the queries.

Result
A formatted preview shows here as you paste.
Runs in your browser. Nothing is uploaded.

What this XPath tester does

XPath is a query language for XML. An expression selects elements, attributes, or text, and it can also count nodes or compute a value. The XPath panel reads your document, runs the expression, and lists what it found.

The panel reads data only, so it never changes your XML. It opens when an XML file is loaded. The box above checks and pretty-prints your XML; it does not run XPath.

What the XPath panel gives you

The panel uses the browser's native XPath engine, which implements XPath 1.0. That sets which functions you can call. These are the groups the docs list, with the other features of the panel.

  • Node-set functions: count(), position(), last(), name(), and local-name().
  • String functions such as contains(), starts-with(), substring(), normalize-space(), translate(), and concat().
  • Boolean functions not(), true(), false(), and boolean().
  • Number functions sum(), round(), floor(), ceiling(), and number().
  • An Examples list and a short XPath Reference beside the input.
  • Namespace prefixes read from your document, listed under Namespaces.

How to test XPath online

Start in the box to check the XML, then use the editor for the query. The steps below go from a pasted document to a list of matches that you can read and test.

  1. Paste your XML into the box, or select Try an example. The box accepts up to 512 KB.
  2. Read the result. It shows a summary and the pretty-printed XML, or the line and column of the first error.
  3. Select Open in full editor. The XML opens in the Tree view. If it has an error, the button reads Fix it in the editor.
  4. In the toolbar, select XPath in the Transform group. You can also press Cmd+K (Ctrl+K on Windows and Linux) and run Query / Transform.
  5. Type an expression, then select the run button or press Enter.
  6. Read the match count and the list of matches. Pick an item from Examples to load it.

Worked example: an Atom feed with a default namespace

This Atom feed declares a default namespace on its root. In XPath 1.0 that matters: an unprefixed name matches only elements with no namespace, so //entry/title finds nothing. The panel adds a prefix named ns for the default namespace.

<feed xmlns="http://www.w3.org/2005/Atom">
  <title>Release notes</title>
  <entry>
    <title>Version 2.1</title>
    <link href="https://example.com/2-1"/>
  </entry>
  <entry>
    <title>Version 2.0</title>
    <link href="https://example.com/2-0"/>
  </entry>
</feed>

//entry/title              No matches found
//ns:entry/ns:title/text() Version 2.1
                           Version 2.0
//ns:entry/ns:link/@href   href="https://example.com/2-1"
                           href="https://example.com/2-0"
count(//ns:entry)          2

Reading the results

A node set lists each match. An element shows as its XML, an attribute shows as name="value", and a text node shows its text. A number, such as the output of count(), shows as a number. A string shows as text, and a boolean shows as true or false.

When a valid query matches nothing, the panel says No matches found. If a query uses a prefix the document does not declare, the panel shows an error and lists the known prefixes. A prefix the document declares with xmlns:prefix works as written.

Expressions worth knowing

A few forms cover most day-to-day questions. Each one below uses a small book catalog, and the Examples list in the panel has more forms you can load with one click.

  • //book selects every book element, wherever it sits in the document.
  • //book[@isbn] keeps only the books that have an isbn attribute.
  • //book/@isbn reads the attribute value itself.
  • /catalog/book[price>30] filters by the value of a child element.
  • //book[last()] picks the last book, and //book[1] picks the first.
  • //title[starts-with(., "Adv")] matches on the start of the text.

Common uses

XPath is the quickest way to answer a narrow question about a large XML file, and a tester saves a round trip through your code. These are typical jobs.

  • Check a selector before you paste it into code, a scraper, or an XSLT file.
  • Read one attribute, such as every isbn or href, from a long document.
  • Count the elements of one kind, for example the items in a feed.
  • Find elements by their text, with contains() or starts-with().
  • Debug a namespace problem when a query returns nothing.

Free and Pro

The XPath panel is part of Pro, a one-time purchase of US$19.99 with lifetime access and no subscription. Free users can open a Pro tool and select Try it free today, which gives one free try of each Pro tool per day. The Tree, Raw, and Table views of XML stay free.

Frequently asked questions

Which XPath version does it use?

XPath 1.0. The panel runs your expression with the native XPath engine of the browser. Functions added in XPath 2.0 and later, such as matches() and lower-case(), are not part of XPath 1.0.

Why does my query return nothing?

The document probably declares a default namespace with xmlns on its root. Unprefixed names then match nothing in XPath 1.0. Use the ns prefix the panel adds, as in //ns:title.

Does the box on this page run XPath?

No. The box checks your XML and shows it pretty-printed. The XPath panel runs in the editor, which the Open in full editor button opens with your document.

Can I test XPath on an RSS or Atom feed?

Yes. A feed is an XML document, so the same panel works on it. Atom feeds usually declare a default namespace, so use the ns prefix for their elements.

Is the XPath tester free?

The XPath panel is a Pro tool. Free users get one free try of it per day. Pro costs US$19.99 once, with lifetime access and no subscription.

Is my XML uploaded?

No. The query runs in your browser, and Prettify does not save queries to disk. Your document leaves the device only if you create a share link.

Related tools