---
title: "XPath for XML: Query Nodes and Attributes | Prettify Docs"
description: Query XML and feeds in Prettify with XPath 1.0. Select nodes,
  attributes, and text, use functions, and work with namespaces. See examples.
url: https://prettify.tools/docs/xpath
---

[Docs](https://prettify.tools/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:

```xml
<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:

```xpath
//book
```

Select books that have an `isbn` attribute:

```xpath
//book[@isbn]
```

Read the title text of each book:

```xpath
//book/title/text()
```

Select books with a price above 30:

```xpath
/catalog/book[price>30]
```

Find an author by text content:

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

Read an attribute value:

```xpath
//book/@isbn
```

Count the books:

```xpath
count(//book)
```

Select the first and the last book:

```xpath
//book[1]
```

```xpath
//book[last()]
```

Match on the start of the text:

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

Sum the prices:

```xpath
sum(//price)
```

## Functions

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

| Group    | Functions                                                                                                                                                              |
| -------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Node set | `count()`, `position()`, `last()`, `name()`, `local-name()`                                                                                                            |
| String   | `contains()`, `starts-with()`, `substring()`, `substring-before()`, `substring-after()`, `string-length()`, `normalize-space()`, `translate()`, `concat()`, `string()` |
| Boolean  | `not()`, `true()`, `false()`, `boolean()`                                                                                                                              |
| Number   | `sum()`, `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:

```xpath
//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](https://prettify.tools/docs/xml)
- [RSS and Atom feeds](https://prettify.tools/docs/rss-feeds)
- [Views](https://prettify.tools/docs/views)
- [Conversion](https://prettify.tools/docs/conversion)
- [Pro features](https://prettify.tools/docs/pro)
- [XML Formatter tool](https://prettify.tools/xml-formatter)

## Try it online

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

- [XPath Tester](https://prettify.tools/xpath-playground)
- [XML Viewer](https://prettify.tools/xml-viewer)

* [PreviousSQL queries](https://prettify.tools/docs/sql)
* [Next Search and replace](https://prettify.tools/docs/search-and-replace)

## Structured data

```json
{
  "@context": "https://schema.org",
  "@type": "SoftwareApplication",
  "name": "Prettify",
  "url": "https://prettify.tools",
  "description": "Multi-format data viewer, editor, and query engine for JSON, YAML, CSV, XML, Mermaid, Markdown, MDX, HTML, and SVG",
  "applicationCategory": "DeveloperApplication",
  "operatingSystem": "Web, macOS, Windows, Linux",
  "offers": [
    {
      "@type": "Offer",
      "price": "0",
      "priceCurrency": "USD",
      "description": "Free tier with core features"
    },
    {
      "@type": "Offer",
      "price": "19.99",
      "priceCurrency": "USD",
      "description": "Pro: lifetime access to all features"
    }
  ],
  "publisher": {
    "@id": "https://prettify.tools/#organization"
  }
}
{
  "@context": "https://schema.org",
  "@type": "Organization",
  "@id": "https://prettify.tools/#organization",
  "name": "Prettify",
  "legalName": "Off Leash Labs",
  "url": "https://prettify.tools/",
  "logo": {
    "@type": "ImageObject",
    "url": "https://prettify.tools/icon-512.png",
    "width": 512,
    "height": 512
  },
  "contactPoint": {
    "@type": "ContactPoint",
    "contactType": "customer support",
    "email": "offleashlabs@gmail.com",
    "availableLanguage": "English"
  }
}
```
