How do I undeclare the default XML namespace?
To "undeclare" the default XML namespace, you declare a
default XML namespace with an empty (zero-length) name
(URI). Within the scope of this declaration, unprefixed
element type names do not belong to any XML namespace.
For example, in the following, the default XML namespace
is the http://www.google.org/ for the A and B elements
and there is no default XML namespace for the C and D
elements. That is, the names A and B are in the http://www.google.org/
namespace and the names C and D are not in any XML
Why are special attributes used to declare XML
I don't know the answer to this question, but the likely
reason is that the hope that they would simplify the
process of moving fragments from one document to another
document. An early draft of the XML namespaces
recommendation proposed using processing instructions to
declare XML namespaces. While these were simple to read
and process, they weren't easy to move to other
documents. Attributes, on the other hand, are intimately
attached to the elements being moved.
Unfortunately, this hasn't worked as well as was hoped.
For example, consider the following XML document:
Simply using a text editor to cut the fragment headed by
the <B> element from one document and paste it into
another document results in the loss of namespace
information because the namespace declaration is not
part of the fragment -- it is on the parent element
(<A>) -- and isn't moved.
Even when this is done programmatically, the situation
isn't necessarily any better. For example, suppose an
application uses DOM level 2 to "cut" the fragment from
the above document and "paste" it into a different
document. Although the namespace information is
transferred (it is carried by each node), the namespace
declaration (xmlns attribute) is not, again because it
is not part of the fragment. Thus, the application must
manually add the declaration before serializing the
document or the new document will be invalid.
How do different XML technologies treat XML namespace
This depends on the technology -- some treat them as
attributes and some treat them as namespace
declarations. For example, SAX1 treats them as
attributes and SAX2 can treat them as attributes or
namespace declarations, depending on how the parser is
configured. DOM levels 1 and 2 treat them as attributes,
but DOM level 2 also interprets them as namespace
declarations. XPath, XSLT, and XML Schemas treat them as
The reason that different technologies treat these
differently is that many of these technologies predate
XML namespaces. Thus, newer versions of them need to
worry both about XML namespaces and backwards
How do I use prefixes to refer to element type and
attribute names in an XML namespace?
Make sure you have declared the prefix and that it is
still in scope . All you need to do then is prefix the
local name of an element type or attribute with the
prefix and a colon. The result is a qualified name,
which the application parses to determine what XML
namespace the local name belongs to.
For example, suppose you have associated the serv prefix
with the http://www.our.com/ito/servers namespace and
that the declaration is still in scope. In the
following, serv:Address refers to the Address name in
the http://www.our.com/ito/servers namespace. (Note that
the prefix is used on both the start and end tags.)
<!-- serv refers to the http://www.our.com/ito/servers
Now suppose you have associated the xslt prefix with the
http://www.w3.org/1999/XSL/Transform namespace. In the
following, xslt:version refers to the version name in
the http://www.w3.org/1999/XSL/Transform namespace:
<!-- xslt refers to the http://www.w3.org/1999/XSL/Transform
How do I use the default XML namespace to refer to
element type names in an XML namespace?
Make sure you have declared the default XML namespace
and that that declaration is still in scope . All you
need to do then is use the local name of an element
type. Even though it is not prefixed, the result is
still a qualified name ), which the application parses
to determine what XML namespace it belongs to.
For example, suppose you declared the
http://www.w3.org/to/addresses namespace as the default
XML namespace and that the declaration is still in
scope. In the following, Address refers to the Address
name in the http://www.w3.org/to/addresses namespace.
<!-- http://www.w3.org/to/addresses is the default XML