Skip to main content
XMLDir

Search 309 pages — tools, formats, elements, namespaces, directory, comparisons, XPath, datatypes, glossary, parse errors, schema errors, use cases, blog and product.

Names and namespaces

Namespace

A URI that qualifies element and attribute names, so identically-named elements from different vocabularies can coexist in one document.

A namespace URI is an identifier, not an address. Nothing fetches it, and it need not resolve — the sitemaps.org URL in every sitemap on the web is compared as a string and never requested. Its only job is to be globally unique.

Namespaces are the single biggest source of surprise for people querying XML, because an unprefixed name in XPath 1.0 means "in no namespace" rather than "in whatever the document's default is". A path copied from the document itself will therefore match nothing.

Defined in
Namespaces in XML 1.0
Category
Names and namespaces
Also written
XML namespace, xmlns

Shown, not asserted

All 2 claims are executed on every test run, against the same engines the tools use. If the behaviour changes, the test fails rather than this page quietly becoming wrong.

  • In a namespaced document, an unprefixed path matches nothing — the classic empty result.

    document.xml
    <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"><url><loc>https://example.com/</loc></url></urlset>
    expression
    count(//loc)

    What the engine returns

    0
  • Matching on the local name instead finds it.

    document.xml
    <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"><url><loc>https://example.com/</loc></url></urlset>
    expression
    count(//*[local-name()='loc'])

    What the engine returns

    1

What catches people out

  • A namespace URI is compared character by character. A trailing slash, or http where the document says https, makes it a different namespace.
  • Nothing is ever fetched from a namespace URI. If yours 404s, no consumer notices.
  • Attributes are not in the default namespace, even in a document that declares one. An unprefixed attribute is in no namespace at all.

Get started

Bring order to the XML your team can't afford to ignore.

Create a free account and get a private workspace to search, validate, diff, and monitor your XML feeds, sitemaps, schemas, and vendor integrations.