PrettifyPrettify
DocsHome
Getting started
  • Getting started
Formats
  • JSON
  • JSONL and NDJSON
  • YAML
  • CSV and TSV
  • XML
  • RSS and Atom feeds
  • Mermaid
  • Markdown
  • MDX
  • HTML
  • SVG
Views
  • Views overview
  • Diagram view
  • Chart view
Queries
  • jq queries
  • SQL queries
  • XPath queries
Editing tools
  • Search and replace
  • Format conversion
  • Transforms
  • Type generation
  • JSON Schema validation
  • Diff and compare
  • Split view
Your documents
  • Tabs
  • History and versions
  • Sharing
  • Privacy and your data
Desktop app
  • Desktop app
  • Keyboard shortcuts
Pro
  • Prettify Pro
Help
  • Troubleshooting

Docs / Queries

XPath queries

Last updated: October 16, 2026

XPath is a query language for XML. The XPath panel selects nodes, attributes, and text from an XML document, including RSS and Atom feeds. The queries run on your device. The XPath panel is a Pro feature. Free users get one free try of it per day.

The panel reads XPath queries with the browser's native XPath engine. That engine implements XPath 1.0. This page shows how to open the panel, run a query, read the result, and work with namespaces.

Open the XPath panel

The XPath panel is available when an XML file is open.

Open the panel in one of two ways:

  1. In the toolbar, select XPath (in the Transform group).
  2. Open the Command Palette with Cmd+K (Mac) or Ctrl+K (Windows, Linux), then run Query / Transform.

The panel title is XPath Query. A Pro badge marks the toolbar button for free users.

Run a query

Type an XPath expression in the input field. Select the run button, or press Enter.

The panel lists Examples on the side. Select one to load it. A short XPath Reference shows common forms.

The panel keeps your last query and result for the session, so they return when you reopen the panel. Prettify does not save queries to disk.

The XPath panel reads data only. It does not change the document.

Read the result

The result depends on what the query returns:

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

The panel shows the match count above the list. It shows No matches found when a valid query matches nothing.

Examples

Every example below uses this document:

<catalog>
  <book isbn="123">
    <title>XPath Basics</title>
    <author>John Doe</author>
    <price>29.99</price>
  </book>
  <book isbn="456">
    <title>Advanced XML</title>
    <author>Jane Roe</author>
    <price>39.99</price>
  </book>
</catalog>

Select every book element:

//book

Select books that have an isbn attribute:

//book[@isbn]

Read the title text of each book:

//book/title/text()

Select books with a price above 30:

/catalog/book[price>30]

Find an author by text content:

//author[contains(text(), "John")]

Read an attribute value:

//book/@isbn

Count the books:

count(//book)

Select the first and the last book:

//book[1]
//book[last()]

Match on the start of the text:

//title[starts-with(., "Adv")]

Sum the prices:

sum(//price)

Functions

The engine supports the XPath 1.0 function library. Common functions include:

GroupFunctions
Node setcount(), position(), last(), name(), local-name()
Stringcontains(), starts-with(), substring(), substring-before(), substring-after(), string-length(), normalize-space(), translate(), concat(), string()
Booleannot(), true(), false(), boolean()
Numbersum(), round(), floor(), ceiling(), number()

Namespaces

XPath 1.0 has no default namespace. An unprefixed name in a query matches only elements that have no namespace. A document that declares xmlns="..." on its root puts every element in a namespace, so an unprefixed query returns nothing.

The panel solves this for you. It reads the namespace declarations from the document. It lists the available prefixes under Namespaces:. For the default namespace, it adds a prefix named ns (or ns1, ns2, and so on when the document already uses ns).

Use the prefix to select elements in the default namespace. For a document with a default namespace, write:

//ns:title

A prefix that the document declares with xmlns:prefix is already usable. For example, //atom:entry works when the feed binds the atom prefix.

If a query uses a prefix the document does not declare, the panel shows an error and lists the known prefixes.

Related pages

  • XML in Prettify
  • RSS and Atom feeds
  • Views
  • Conversion
  • Pro features
  • XML Formatter tool

Try it online

Tool pages for this topic. Each one runs in your browser.

  • XPath Tester
  • XML Viewer
PreviousSQL queriesNext Search and replace
On this page
  • Open the XPath panel
  • Run a query
  • Read the result
  • Examples
  • Functions
  • Namespaces
  • Related pages
Prettify·Home·All docs·Contact·Changelog·Open app·llms.txtPermalink