[This local archive copy mirrored from the canonical site: http://www.w3.org/TR/1998/WD-xml-names-19980518.html; links may not have complete integrity, so use the canonical document at this URL if possible.]
Copyright © 1998 W3C (MIT, INRIA, Keio ), All Rights Reserved. W3C liability, trademark, document use and software licensing rules apply.
This draft specification is a work in progress representing the current consensus of the W3C XML Working Group. This is a W3C Working Draft for review by W3C members and other interested parties. Publication as a working draft does not imply endorsement by the W3C membership. While we do not anticipate substantial changes, we still caution that further changes are possible and therefore we recommend that only experimental software or software that can be easily field-upgraded be implemented to this specification at this time. The XML Working Group will not allow early implementation to constrain its ability to make changes to this specification prior to final release. This is a draft document and may be updated, replaced or obsoleted by other documents at any time. It is inappropriate to cite W3C Working Drafts as other than "work in progress".
It is the intent of the XML Working Group that this namespace facility should become an integral part of some future version of the XML specification.
XML namespaces provide a simple method for qualifying names used in Extensible Markup Language documents by associating them with namespaces identified by URI.
We envision applications of Extensible Markup Language [XML] where a document contains markup defined in multiple schemas, which may have been authored independently. One motivation for this is that writing good schemas is hard, so it is beneficial to re-use parts from existing, well-designed schemas. Another is the advantage of allowing search engines or other tools to operate over a range of documents that vary in many respects but use common names for common element types.
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.
XML namespaces are based on the use of qualified names, which contain a single colon, separating the name into a namespace prefix and the local name. The prefix, which is mapped to a URI, selects a namespace. The combination of the universally managed URI namespace and the local name produces names that are guaranteed universally unique.
URIs 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. A special processing instruction described below is used to declare the association of the namespace prefix with a URI; software which supports this namespace proposal must recognize and act on it.
[Definition:] A namespace is declared using a reserved processing instruction as follows:
|Namespace Declaration PI|
is a URI which functions as a namespace name to identify
is an optional URI which may be used to retrieve the schema, if one
Some namespaces need no
schemas; this specification does not depend on their existence, or on the use
of any particular machine- or human-readable syntax in the schema.
NCName in the
production gives the namespace prefix
used to associate names in an XML document
with this namespace.
A namespace declaration must contain exactly one
NSDef, exactly one
PrefixDef and zero or one
production must contain a URI,
not including an attached
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.
Examples of namespace declarations:
Namespace declarations must be located in the prolog of an XML document, after the XML Declaration (if any) and before the DTD (if any). This effectively makes the scope of namespace prefixes global to the whole document, including the DTD. It also means that should a processor wish to insert its own qualified names, it need only read the namespace declarations from the prolog to be sure of generating a new, unique, namespace prefix.
In XML documents conforming to this specification, the
must match the following production:
|Prolog with Namespace Declarations|
Note that the namespace declarations are ordinary processing instructions which the XML processor will pass to the application as it does any other.
A namespace prefix may not be declared more than once; i.e. there may not be two
PrefixDefs which contain the same
[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
LocalPart provides the
local name part of the qualified name.
Note that the prefix functions only as a placeholder for a namespace name. Applications should use the namespace name and local name pair whenever a name is required whose scope extends beyond the containing document.
The namespace prefix, unless it is "
xml", must have been
declared in a namespace declaration.
The namespace prefix
xml is reserved, and considered to
have been implicitly declared.
No other prefix beginning with the three-letter sequence
l, in any case combination, is allowed.
In XML documents conforming to this specification,
element types are given as
qualified names, as
In the productions below, the nonterminals
are taken from the XML specification [XML];
the productions in all cases match a subset of the strings matched by those of
the same name in the XML spec.
|Element Types and Attribute Names|
Attribute names are given as qualified names, as follows:
An attribute whose name is not qualified, but which is attached to an element whose type is qualified, is in the namespace of the element type prefix. This specification does not provide a syntactic mechanism for determining whether the significance of, or definition for, the attribute is dependent on the element type to which it is attached; see "2.5 Ambiguity In Attributes".
Element names and attribute types are also given as qualified names when they appear in declarations in the DTD:
|Qualified Names in Declarations|
Processing instruction targets
are given as
Declare Before Use
When a PI target, aside from that in a namespace declaration PI, is qualified with a prefix, that prefix must be declared at a location in the document which precedes its use.
When a schema is provided for a namespace, there is no guarantee that the combination of namespace name and attribute name will provide sufficient information to locate the appropriate description in the schema (if any exists) for the attribute. The XML document type definition is an example of a schema language in which this is possible. In a DTD, many attributes can be declared which share a name; they are distinguished by being attached to different element types.
This ambiguity is not always a problem.
Consider one of the HTML 4.0
DTDs, which define two attributes,
for use with stylesheets.
The DTD and accompanying description define
this attribute in such a way that it may apply to
virtually every element, and that its semantics are identical wherever
Thus, given a prefix
html which selects a
namespace whose schema is that of
HTML 4.0, the following would present no problems:
On the other hand, consider a document that uses data types
defined by ISO Standard 31, which deals with units of measure.
In ISO 31, the unit "degrees" can apply
to measures of several very different quantities.
Thus, assuming the prefix
ISO denotes a namespace associated with
ISO 31, whatever the schema language in use, the following would almost
certainly be ambiguous:
To make this more concrete, consider a schema which is an XML DTD containing the following declarations:
Suppose that in some document this DTD is associated with a namespace
identified by the
Then, in the following example, the syntax described in this specification
does not provide sufficient information to distinguish
T:Temp is the
Temp attribute associated with
Heat element, or that associated with the
In practical terms, it is expected that applications which process
attributes will have built-in knowledge as to their meaning and the effect (if
any) of their element context.
Thus this should not be problem operationally.
However, it can in general be addressed by using multiple
In the immediately preceding example, it would be necessary to
declare namespaces with prefixes, for example,
TempColor, whose associated
namespace names would select the parts of
the schema that described, respectively, the attributes of the
Then the example could be disambiguated as follows:
Names in XML documents which conform to this specification are
element types, attribute names and PI targets which match the production for
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 in principle only available
in documents which have been
Thus, in well-formed XML
documents, there can be no assurance that the contents of attribute values
have been checked for conformance to this specification.
Imagine an XML document representing an invoice for books. If public schemas exist for elements and attributes describing books, electronic transactions and digital signatures, the invoice author should be able to use these, rather than inventing new element and attribute types. Any reader of the invoice document should be able to infer a consistent meaning to its contents, the same meaning as if the elements and attributes had appeared in a different kind of document (such as an invoice for automotive parts, or an inventory of books or a digital signature on a legal contract). A search tool should be able to locate the elements, regardless of the document in which they reside. Further, since several schemas may choose the same name (e.g. "size") for elements or attributes with different meanings, these must be distinguished if used within the same document.
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.