---
title: "Why XPath returns no results with a default namespace"
description: "Understand why XPath 1.0 misses elements in a default XML namespace, and use namespace-aware expressions with a worked catalog example."
author: "XML Lens editorial"
datePublished: 2026-09-26
dateModified: 2026-10-23
canonical: https://xmllens.ayushdev.com/guides/xpath-default-namespace
---

# Why XPath returns no results with a default namespace

In XPath 1.0, an unprefixed element name selects elements in no namespace. If your XML declares a default namespace, an expression such as /catalog/book will not select those namespaced elements.

XML Lens editorial · Reviewed 2026-10-23

## A small document that explains the problem

Consider a catalog from a supplier. The element names look familiar, but the default namespace gives catalog, book, and title a namespace URI. The id attribute remains unnamespaced.

```
<catalog xmlns="urn:example:books">
  <book id="b1">
    <title>Field Notes</title>
  </book>
</catalog>

<!-- XPath 1.0: no matching elements -->
/catalog/book/title
```

## Use a prefix bound to the namespace URI

In an XPath tool that exposes namespace bindings, bind a query prefix such as b to urn:example:books, then qualify each element step. The query prefix is a label for the URI; it need not appear in the original document.

Namespace-binding controls differ by tool. In XML Lens, inspect a node’s namespace and generated XPath first rather than assuming a particular manually entered prefix has been registered.

```
# With b bound to urn:example:books
/b:catalog/b:book/b:title

# Filter on the unnamespaced id attribute
/b:catalog/b:book[@id="b1"]/b:title
```

## An explicit expression without a prefix binding

For this example, match both the local name and the namespace URI. This is longer, but it makes the namespace requirement explicit without relying on a prefix configuration.

```
/*[local-name()="catalog" and namespace-uri()="urn:example:books"]
 /*[local-name()="book" and namespace-uri()="urn:example:books"]
 /*[local-name()="title" and namespace-uri()="urn:example:books"]
```

- The expected result is one title element containing Field Notes.
- Use the URI exactly as declared in the document.
- Checking only local-name() can mix elements from different namespaces.

## Debug one step at a time

Start at the root and add one path step at a time. If the first step matches and the next does not, inspect the next element’s name and namespace rather than changing the entire query.

Also check context: an absolute path begins at the document root, while a relative path starts from the current context node. A correct relative expression can return nothing when evaluated from the wrong place.

Save the working expression with a short note about its namespace assumptions. When a supplier changes its export format, that note helps you distinguish a data change from a query error.

## Common questions

### Should I remove xmlns to make the query work?

No. Removing a namespace changes the identity of the elements and may break validation or downstream processing. Adapt the query to the document.

### Does a default namespace apply to an unprefixed attribute?

No. In the catalog example, id is unnamespaced even though book belongs to urn:example:books.

## References

- [W3C XPath 1.0: node tests](https://www.w3.org/TR/1999/REC-xpath-19991116/#node-tests)
- [W3C Namespaces in XML: namespace defaulting](https://www.w3.org/TR/xml-names/#defaulting)

## Try the workflow in XML Lens

[Download XML Lens for Mac](https://apps.apple.com/us/app/xml-editor-lens-xpath/id6761771384?mt=12&ct=guide-xpath-default-namespace)

Explore the relevant Mac workspaces and their capabilities.

- [Query XML with XPath 1.0 on your Mac](https://xmllens.ayushdev.com/xpath-xml-mac)
- [See any XML document as an interactive map](https://xmllens.ayushdev.com/xml-visual-map)
- [View and format XML locally on Mac](https://xmllens.ayushdev.com/xml-viewer-formatter)

[All XML guides](https://xmllens.ayushdev.com/guides)
