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:
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
e5 are in
the namespace named by
e6, and all instances of
a1, are not in any namespace whatsoever.
This example also shows why you can’t have a “blank”
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
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.