Names and namespaces
Default namespace
The namespace declared by a bare xmlns="…", which applies to unprefixed element names on that element and its descendants.
Almost every real XML format uses one: sitemaps, Atom feeds, SVG and XSD all declare a default namespace on the root so their elements can be written without prefixes. That makes documents pleasant to read and queries surprising to write, because the elements are namespaced even though nothing in the markup says so on each line.
It can also be turned off. An xmlns="" on an element puts that element and its unprefixed descendants back into no namespace at all, which is how a mixed document embeds a fragment from an unnamespaced vocabulary.
- Defined in
- Namespaces in XML 1.0 §6.2
- Category
- Names and namespaces
- Also written
- xmlns=, unprefixed namespace
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.
xmlns="" undeclares the default namespace, so an unprefixed path matches the inner element again.
document.xml <r xmlns="urn:a"><c xmlns=""/></r>expression count(//c)What the engine returns
1The outer element is still namespaced, so the same style of path misses it.
document.xml <r xmlns="urn:a"><c xmlns=""/></r>expression count(//r)What the engine returns
0
What catches people out
- A default namespace never applies to attributes. An unprefixed attribute is in no namespace, whatever the element declares.
- XPath 1.0 has no concept of a default namespace for queries. You must bind a prefix or match on local-name().
- Removing a default namespace declaration from a document changes the meaning of every element in it, even though the tags look identical.
Where it bites
A definition on its own is trivia. These are the pages where this term decides whether a document works.
- FormatsAtom 1.0A format whose whole vocabulary sits in a default namespace.
- NamespacesAtom Syndication Format 1.0The URI that default declaration names.
- XPathlocal-name()The workaround when your XPath engine cannot bind a prefix.
Related terms
- NamespaceA URI that qualifies element and attribute names, so identically-named elements from different vocabularies can coexist in one document.
- Namespace prefixThe short NCName bound to a namespace URI by an xmlns:prefix declaration, used before a colon to qualify names.
- AttributeA name–value pair on an element's start tag, whose value is always a quoted string.
- 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.
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.