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
0Matching 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.
Where it bites
A definition on its own is trivia. These are the pages where this term decides whether a document works.
- NamespacesSitemap protocol 0.9The URI every sitemap declares, and the one most often mistyped.
- XPathlocal-name()The usual way out when you cannot bind a prefix.
- ToolsXPath explorerLists every path in a document with its namespace, so you can see what is really there.
Related terms
- Namespace prefixThe short NCName bound to a namespace URI by an xmlns:prefix declaration, used before a colon to qualify names.
- Default namespaceThe namespace declared by a bare xmlns="…", which applies to unprefixed element names on that element and its descendants.
- Expanded nameThe pair of namespace URI and local name that a QName resolves to — what processors actually compare when they match a name.
- QNameA qualified name: an optional namespace prefix, a colon, and a local name — the form every element and attribute name takes in a namespaced document.
- Target namespaceThe namespace a schema's declarations belong to, named by the targetNamespace attribute on xs:schema.
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.