Skip to content
Marvin's Toolbox.

Search tools

Type to filter all tools

XPath Playground

Run XPath queries against your own XML or HTML and see the matching nodes right away. Shows each match with its path and value, handles namespaces, and comes with examples for the syntax you keep forgetting.

Everything runs locally in your browser. Your data never leaves your device.

Examples

Result

Namespaces

Prefixes an expression can use, mapped to the namespace URIs in the document.

This document declares no namespaces, so plain names like //book match right away.

XPath 1.0 has no default namespace. A document that starts with xmlns="…" puts every element in that namespace, and an unprefixed name like //book then matches nothing at all. Bind a prefix to the URI here and write //ns:book, or sidestep the whole thing with //*[local-name(.)='book']. The prefix is yours to pick, it does not have to be the one in the document. HTML pages need none of this.

Cheat sheet

Click any row to load a working expression for the book catalog sample.

Steps and paths

Predicates

Functions

Axes

Expressions run through the browser's own XPath engine, the same one behind $x() in devtools. That engine speaks XPath 1.0, so XPath 2.0 and 3.1 additions like matches(), tokenize() or for loops are not available.

Next steps

Send this tool's output straight into another tool.

Format code in JavaScript, TypeScript, JSON, JSON5, HTML, Vue, CSS, SCSS, LESS, Markdown, YAML, GraphQL, XML and SQL. Pick tabs or spaces, set the indent width, and format the input in place with one click.

Convert config and data between JSON, YAML, TOML, JSON5, INI, XML, CSV and .env. Type or paste on the left, pick the output format on the right, and copy the result. Includes a format button and a minify toggle.

Paste JSON to explore it as a collapsible, searchable tree, hide the fields you don't need, and see the structure it implies as a badge-annotated schema and a copyable TypeScript interface.

Compare two JSON documents by structure and see every added, removed and changed key and value with its exact path. Browse the result as a tree, a filterable change list or a line diff, ignore array order, catch type changes and export the changes as a JSON report.

Convert text into every case at once: title case in the APA, AP, Chicago, MLA, Bluebook, AMA and NYT styles, sentence case, upper, lower, camelCase, snake_case, kebab-case and more.

Count words, characters, sentences, paragraphs, lines and more as you type, with estimated reading and speaking time.

Remove duplicate lines from a list or text, keeping the first occurrence. Optionally ignore case and whitespace, or drop blank lines too.

Replace text in two modes: plain find and replace all, or regular expressions with flag controls and capture group references like $1.

Compare two texts and see every added, removed and changed line highlighted, side by side or inline, with the changed words marked within each line. Ignore case, whitespace or blank lines, read a summary of how much changed, and export the result as a unified diff.

About the XPath Playground Tool

This tool runs XPath expressions against your own XML or HTML and shows what they match while you type. Every match comes with its node kind, its value and the absolute location path that points at it, so finding the address of a node is as quick as reading its content.

It ships with a book catalog, an Atom feed and a small HTML page, plus example expressions and a cheat sheet for each of them. That makes it a place to learn the syntax as much as a place to test the expression you are about to paste into a scraper or a config file.

What you can do

  • Test an XPath expression against your own XML before using it in code.
  • Write and check an XPath selector for a web page or a Selenium test.
  • Find the full path to a node in an XML document and copy it.
  • Query XML that uses namespaces, with a prefix table you can edit.
  • Extract attribute values, text nodes or whole elements from a document.
  • Count or sum values with count(), sum() and string().
  • Learn XPath from clickable examples, axes, predicates and functions.

How to use the XPath Playground

  1. 1Paste your XML or HTML into the document editor, or load one of the samples.
  2. 2Pick XML or HTML. XML parsing is strict and names the first error, HTML parsing accepts the usual unclosed tags.
  3. 3Type an XPath expression, or click an example to load one.
  4. 4Read the matches below. Each one shows its kind, its serialized value and its location path.
  5. 5Copy the values, the paths or the matched XML, download the result, or send it to the next tool.

The same engine as your devtools

Expressions run through the XPath engine that is already part of the browser, the one behind $x() in the devtools console and behind document.evaluate() in code. What matches here is exactly what matches there, which is the point of testing an expression before you ship it. The Copy as $x() button gives you the expression ready to paste into a console.

That engine speaks XPath 1.0, the version every browser implements. XPath 2.0 and 3.1 additions like matches(), tokenize(), for loops or sequence types are not available anywhere in a browser, so an expression written for Saxon or a Java library may need trimming. Everything in the cheat sheet works.

Namespaces and the unprefixed name trap

XPath 1.0 has no default namespace. If a document starts with <feed xmlns="http://www.w3.org/2005/Atom">, every element in it belongs to that namespace, and //entry matches nothing at all, however right it looks. The name has to be written with a prefix that is bound to the URI, like //atom:entry.

The prefix table collects what the document declares and invents a readable prefix for the default namespace, so a namespaced feed is queryable the moment you paste it. The prefixes are yours to rename, and they do not have to match the ones in the source. When an expression comes back empty because of this, the result panel says so and offers to add the prefix for you. The other way out is //*[local-name(.)='entry'], which ignores namespaces entirely.

Node sets, strings, numbers and booleans

An XPath expression does not always return nodes. count(//book) gives a number, string(//title) a string, and a comparison or boolean(…) gives true or false. All four come back here, labelled with their type, instead of an empty list that looks like a mistake.

For a node set, each match is listed with its kind (element, attribute, text, comment or processing instruction), the node serialized back to XML and its location path, for example /catalog/book[2]/title. Steps are numbered only where a name repeats, so paths stay readable, and Number every path step switches to the fully numbered form that some tools expect.

XPath on HTML pages

HTML mode uses the forgiving HTML parser, so a page saved from a site works even with unclosed tags, stray attributes and no XML declaration. Unprefixed names match HTML elements directly, which is why selectors like //a[@class='external']/@href behave the same as in a scraper or a browser test.

If a paste fails to parse as XML and looks like a web page, the error offers to switch modes with one click, instead of leaving you with a mismatched-tag message you cannot fix.

XPath, JSONPath or jq

XPath queries markup. For JSON, the same job is done by JSONPath in the JSONPath Playground, and heavier reshaping of JSON belongs in the jq Playground. If the document you have is XML but the tool you feed it to wants JSON, convert it first with the Config Converter and query the result there.

Encode and decode Base16, Base32, Base36, Base45, Base58, Base62, Base64 and Base85. Pick the alphabet variant you need, from Crockford Base32 to Bitcoin Base58 and Ascii85, and convert in either direction.

Decode Base64 to text or encode text to Base64. Paste into the top box, read the result below, and flip the direction with one click. Handles Unicode correctly, reads URL-safe Base64, and shows binary payloads as a hex dump you can download.

Format code in JavaScript, TypeScript, JSON, JSON5, HTML, Vue, CSS, SCSS, LESS, Markdown, YAML, GraphQL, XML and SQL. Pick tabs or spaces, set the indent width, and format the input in place with one click.

Open a CSV or TSV file and read it as a proper table. Sort by any column, filter rows with a search or per-column conditions, hide columns you do not need, and copy or download what is left.

Remove duplicate lines from a list or text, keeping the first occurrence. Optionally ignore case and whitespace, or drop blank lines too.

Replace text in two modes: plain find and replace all, or regular expressions with flag controls and capture group references like $1.