XML Namespaces
Namespaces provide a way to disambiguate names in XML documents, thus helping avoid a collision of names when multiple vocabularies are combined.
Examples
Default namespace declaration
<message xmlns="http://simonstl.com/ns/examples/message
"
xml:lang="en" date="20051006" >
This is a message!
</message>
Qualified or prefixed namespace declaration
<msg
:messagexmlns:msg="http://simonstl.com/ns/examples/
message
" xml:lang="en" date="20051006" > This is a message! </msg
:message>
Description
The special xmlns
attribute, or xmlns
with a prefix
(for example, xmlns:xsl
),
specifies a namespace declaration.
Tip
Namespaces can be confusing because they can use any URI as
a namespace name. The scheme or protocol name http://
suggests that the URI identifies
a resource that can be retrieved just like any other web resource
using Hypertext Transfer Protocol. But this is not the case. The
URI is considered simply a name and is not a guarantee of the
location or existence of a resource. URIs are allocated locally,
so you don’t have to deal with a global registry in order to use
them; however, the downside of this is you can’t really police
people who might use a domain name you own as part of their
URI.
Without a prefix, the xmlns
attribute and its value (such as http://simonstl.com/ns/examples/message) are
considered a default namespace declaration. A default
namespace declaration associates a namespace name—a URI—with one or more
elements; however, a default namespace declaration
never
Get XML Pocket Reference, 3rd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.