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

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

    1
  • The 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.

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.