There is one aspect of XML namespaces that keeps confusing people, and since I wrote the specification, it’s at least partly my fault. In the last week alone it’s caught both Jon Udell and Aaron Swartz. There is no such thing as the “blank namespace” or the “empty namespace” or the “unqualified namespace.” An element or an attribute is either in a namespace or not, and if it’s in a namespace, the namespace has a name, and the name isn’t blank. I enclose an example and a bit more explanation.

The Namespaces in XML Recommendation defines a condition called “being in a namespace” which can apply to elements and attributes in XML documents. (The Recommendation does not define, in any useful sense, what a namespace is, but that fortunately need not concern us here today.) It’s probably easiest to illustrate this by example:

<ns1:e1 xmlns:ns1="http://ns1.example.com/">
  <ns1:e2 a1="1" ns1:a2="2" />
  <e3 a1="1" ns1:a2="2" />
  <e4 xmlns="http://ns2.example.com/">
    <e5 a1="1" ns1:a2="2" />
    <e6 xmlns="" a1="1" ns1:a2="2" />
  </e4>
</ns1:e1>

In this example:

  • The elements e1 and e2, and all instances of the attribute a2, are in the namespace named by http://ns1.example.com/, as are all instances of the attribute a2.

  • The elements e4 and e5 are in the namespace named by http://ns2.example.com/.

  • The elements e3 and e6, and all instances of the attribute a1, are not in any namespace whatsoever.

This example also shows why you can’t have a “blank” namespace. In the start-tag of e4 the default namespace is set to http://ns2.example.com/, but then the empty string is used to unset it again in e6. Since the empty string is used this way, it can’t (by definition) be used to name namespace.

Postscript · Experience has shown that some aspects of this design are probably wrong. I’m not here to defend the design, just to explain how it works and help keep the terminology straight.


author · Dad
colophon · rights
picture of the day
August 08, 2003
· Technology (90 fragments)
· · XML (136 more)

By .

The opinions expressed here
are my own, and no other party
necessarily agrees with them.

A full disclosure of my
professional interests is
on the author page.

I’m on Mastodon!