[This local archive copy is from the official and canonical URL, http://www.w3.org/TR/1999/REC-xml-names-19990114/; please refer to the canonical source document if possible.]
Copyright © 1999 W3C (MIT, INRIA, Keio ), All Rights Reserved. W3C liability, trademark, document use and software licensing rules apply.
This document has been reviewed by W3C Members and other interested parties and has been endorsed by the Director as a W3C Recommendation. It is a stable document and may be used as reference material or cited as a normative reference from another document. W3C's role in making the Recommendation is to draw attention to the specification and to promote its widespread deployment. This enhances the functionality and interoperability of the Web.
The list of known errors in this specification is available at http://www.w3.org/XML/xml-names-19990114-errata.
Please report errors in this document to firstname.lastname@example.org.
XML namespaces provide a simple method for qualifying element and attribute names used in Extensible Markup Language documents by associating them with namespaces identified by URI references.
We envision applications of Extensible Markup Language (XML) where a single XML document may contain elements and attributes (here referred to as a "markup vocabulary") that are defined for and used by multiple software modules. One motivation for this is modularity; if such a markup vocabulary exists which is well-understood and for which there is useful software available, it is better to re-use this markup rather than re-invent it.
Such documents, containing multiple markup vocabularies, pose problems of recognition and collision. Software modules need to be able to recognize the tags and attributes which they are designed to process, even in the face of "collisions" occurring when markup intended for some other software package uses the same element type or attribute name.
These considerations require that document constructs should have universal names, whose scope extends beyond their containing document. This specification describes a mechanism, XML namespaces, which accomplishes this.
[Definition:] An XML namespace is a collection of names, identified by a URI reference [RFC2396], which are used in XML documents as element types and attribute names. XML namespaces differ from the "namespaces" conventionally used in computing disciplines in that the XML version has internal structure and is not, mathematically speaking, a set. These issues are discussed in "A. The Internal Structure of XML Namespaces".
[Definition:] URI references which identify namespaces are considered identical when they are exactly the same character-for-character. Note that URI references which are not identical in this sense may in fact be functionally equivalent. Examples include URI references which differ only in case, or which are in external entities which have different effective base URIs.
Names from XML namespaces may appear as qualified names, which contain a single colon, separating the name into a namespace prefix and a local part. The prefix, which is mapped to a URI reference, selects a namespace. The combination of the universally managed URI namespace and the document's own namespace produces identifiers that are universally unique. Mechanisms are provided for prefix scoping and defaulting.
URI references can contain characters not allowed in names, so cannot be used directly as namespace prefixes. Therefore, the namespace prefix serves as a proxy for a URI reference. An attribute-based syntax described below is used to declare the association of the namespace prefix with a URI reference; software which supports this namespace proposal must recognize and act on these declarations and prefixes.
Note that many of the nonterminals in the productions in this specification are defined not here but in the XML specification [XML]. When nonterminals defined here have the same names as nonterminals defined in the XML specification, the productions here in all cases match a subset of the strings matched by the corresponding ones there.
In this document's productions,
NSC is a "Namespace Constraint",
one of the rules that documents conforming to this specification must follow.
Note that all Internet domain names used in
examples, with the exception of
w3.org, are selected
at random and should not be taken as having any import.
[Definition:] A namespace is
a family of reserved attributes.
Such an attribute's name must either
xmlns or have
xmlns: as a prefix.
These attributes, like any other XML attributes, may be provided
directly or by default.
|Attribute Names for Namespace Declaration|
[Definition:] The attribute's value, a URI reference, is the namespace name identifying the namespace. The namespace name, to serve its intended purpose, should have the characteristics of uniqueness and persistence. It is not a goal that it be directly usable for retrieval of a schema (if any exists). An example of a syntax that is designed with these goals in mind is that for Uniform Resource Names [RFC2141]. However, it should be noted that ordinary URLs can be managed in such a way as to achieve these same goals.
[Definition:] If the
attribute name matches
NCName gives the namespace prefix,
used to associate element and attribute names with the
namespace name in the attribute value
in the scope of the element to which the declaration
In such declarations, the namespace name may not be empty.
[Definition:] If the
attribute name matches
namespace name in the
attribute value is
that of the default namespace
in the scope of the element to which the declaration
In such a default declaration, the attribute value may be empty.
Default namespaces and overriding of declarations are discussed in
"5. Applying Namespaces to Elements and Attributes".
An example namespace declaration, which associates the
edi with the namespace name
Prefixes beginning with the three-letter sequence
l, in any case combination, are reserved
for use by XML and XML-related specifications.
[Definition:] In XML
documents conforming to this specification, some
names (constructs corresponding to the nonterminal
may be given as qualified names, defined as follows:
Prefix provides the
part of the qualified name, and must be associated with a namespace URI
reference in a
LocalPart provides the
local part of the qualified name.
Note that the prefix functions only as a placeholder for a namespace name. Applications should use the namespace name, not the prefix, in constructing names whose scope extends beyond the containing document.
In XML documents conforming to this specification, element types are given as qualified names, as follows:
An example of a qualified name serving as an element type:
Attributes are either namespace declarations or their names are given as qualified names:
An example of a qualified name serving as an attribute name:
The namespace prefix, unless it is
xmlns, must have been
declared in a namespace declaration
attribute in either the start-tag of the element where the prefix
is used or in an an ancestor element (i.e. an element in whose
prefixed markup occurs).
xml is by definition bound to the
xmlns is used only for namespace bindings
and is not itself bound to any namespace name.
This constraint may lead to operational difficulties in the case where the namespace declaration attribute is provided, not directly in the XML document entity, but via a default attribute declared in an external entity. Such declarations may not be read by software which is based on a non-validating XML processor. Many XML applications, presumably including namespace-sensitive ones, fail to require validating processors. For correct operation with such applications, namespace declarations must be provided either directly or via default attributes declared in the internal subset of the DTD.
Element names and attribute types are also given as qualified names when they appear in declarations in the DTD:
|Qualified Names in Declarations|
The namespace declaration is considered to apply to the
element where it is specified and to all elements within the content
of that element, unless overridden by another namespace declaration
with the same
Multiple namespace prefixes can be declared as attributes of a single element, as shown in this example:
A default namespace is considered to apply to the element where it is declared (if that element has no namespace prefix), and to all elements with no prefix within the content of that element. If the URI reference in a default namespace declaration is empty, then unprefixed elements in the scope of the declaration are not considered to be in any namespace. Note that default namespaces do not apply directly to attributes.
A larger example of namespace scoping:
The default namespace can be set to the empty string. This has the same effect, within the scope of the declaration, of there being no default namespace.
In XML documents conforming to this specification, no tag may contain two attributes which:
For example, each of the
bad start-tags is illegal in the
However, each of the following is legal, the second because the default namespace does not apply to attribute names:
In XML documents which conform to this specification,
element types and attribute names must match the production for
must satisfy the "Namespace Constraints".
An XML document conforms to this specification if all other
tokens in the document which are required, for XML conformance, to match the
XML production for
this specification's production for
The effect of conformance is that in such a document:
Strictly speaking, attribute values declared to be of types
NOTATION are also
and thus should be colon-free.
However, the declared type of attribute values is only available
to processors which read markup declarations, for example
Thus, unless the use of a validating processor has been specified,
there can be no assurance that the contents of attribute values
have been checked for conformance to this specification.
In the computing disciplines, the term "namespace" conventionally refers to a set of names, i.e. a collection containing no duplicates. However, treating the names used in XML markup as such a namespace would greatly impair their usefulness. The primary use of such names in XML documents is to enable identification of logical structures in documents by software modules such as query processors, stylesheet-driven rendering engines, and schema-driven validators. Consider the following example:
In this example, there are three occurrences of the name
within markup, and the name alone clearly provides insufficient information
to allow correct processing by a software module.
Another problematic area comes from the use of "global" attributes, as illustrated by this example, a fragment of an XML document which is to be displayed using a CSS stylesheet:
In this case, the
CLASS attribute, which describes the fare basis
and takes values such as "J", "Y", and "C", is distinct at all semantic levels
HTML:CLASS attribute, which
is used to
simulate syntactic richness in HTML, as a means of overcoming the
limited element repertoire by subclassing.
XML 1.0 does not provide a built-in way to declare "global" attributes;
items such as the HTML
CLASS attribute are global only in their
prose description and their interpretation by HTML applications.
However, such attributes, an important distinguishing feature of which is that
their names are unique, are commonly observed to occur in a variety of
In order to support the goal of making both qualified and unqualified names useful in meeting their intended purpose, we identify the names appearing in an XML namespace as belonging to one of several disjoint traditional (i.e. set-structured) namespaces, called namespace partitions. The partitions are:
In XML documents conforming to this specification, the names of all qualified (prefixed) attributes are assigned to the global attribute partition, and the names of all unqualified attributes are assigned to the appropriate per-element-type partition.
For convenience in specifying rules and in making comparisons, we define an expanded form, expressed here in XML element syntax, for each element type and attribute name in an XML document.
type is expressed as an empty XML element of type
It has a required
type attribute which
gives the type's
LocalPart, and an optional
ns attribute which, if the element is qualified, gives its
attribute name is expressed as an empty XML element of type
It has a required
name attribute which gives the name.
If the attribute is global, it has a required
which gives the namespace name;
otherwise, it has a required attribute
gives the type of the attached element, and an optional attribute
elns which gives the namespace name, if known, of the
Slight variations on the examples given above will illustrate the working of expanded element types and attribute names. The following two fragments are each followed by a table showing the expansion of the names:
The names would expand as follows:
|1||section||<ExpEType type="section" ns="urn:com:books-r-us" />|
|2||title||<ExpEType type="title" ns="urn:com:books-r-us" />|
|3||signing||<ExpEType type="signing" ns="urn:com:books-r-us" />
|4||author||<ExpEType type="author" ns="urn:com:books-r-us" />|
|4||title||<ExpAName name='title' eltype="author" elns="urn:com:books-r-us" />
|4||name||<ExpAName name='name' eltype="author" elns="urn:com:books-r-us" />|
|5||book||<ExpEType type="book" ns="urn:com:books-r-us" />|
|5||title||<ExpAName name='title' eltype="book" elns="urn:com:books-r-us" />|
|5||price||<ExpAName name='price' eltype="book" elns="urn:com:books-r-us" />|
|1||RESERVATION||<ExpEType type="RESERVATION" />|
|2||NAME||<ExpEType type="NAME" />|
|2||HTML:CLASS||<ExpAName name="CLASS" ns=http://www.w3.org/TR/REC-html40 />|
|3||SEAT||<ExpEType type="SEAT" />|
|3||CLASS||<ExpAName name="CLASS" eltype="SEAT">|
|3||HTML:CLASS||<ExpAName name="CLASS" ns="http://www.w3.org/TR/REC-html40" />|
|4||HTML:A||<ExpEType type="A" ns="http://www.w3.org/TR/REC-html40" />|
|4||HREF||<ExpAName name="HREF" eltype="A" elns="http://www.w3.org/TR/REC-html40" />|
|5||DEPARTURE||<ExpEType type="DEPARTURE" />|
The constraint expressed by "5.3 Uniqueness of Attributes" above may straightforwardly be implemented by requiring that no element have two attributes whose expanded names are equivalent, i.e. have the same attribute-value pairs.
This work reflects input from a very large number of people, including especially the members of the World Wide Web Consortium XML Working Group and Special Interest Group and the participants in the W3C Metadata Activity. The contributions of Charles Frankston of Microsoft were particularly valuable.