Namespaces in XML 1.0 (Third Edition) (original) (raw)
2 XML Namespaces
2.1 Basic Concepts
[Definition: An XML namespace is identified by a URI reference [RFC3986]; element and attribute names may be placed in an XML namespace using the mechanisms described in this specification. ]
[Definition: An expanded name**is a pair consisting of a namespace nameand alocal name. ] [Definition: For a name N in a namespace identified by a URII, thenamespace nameis I. For a name N that is not in a namespace, thenamespace namehas no value. ] [Definition: In either case thelocal name**is N. ] It is this combination of the universally managed URI namespace with the vocabulary's local names that is effective in avoiding name clashes.
URI references can contain characters not allowed in names, and are often inconveniently long, so expanded names are not used directly to name elements and attributes in XML documents. Insteadqualified namesare used. [Definition: A qualified nameis a name subject to namespace interpretation. ] In documents conforming to this specification, element and attribute names appear as qualified names. Syntactically, they are eitherprefixed names orunprefixed names. An attribute-based declaration syntax is provided to bind prefixes to namespace names and to bind a default namespace that applies to unprefixed element names; these declarations are scoped by the elements on which they appear so that different bindings may apply in different parts of a document. Processors conforming to this specification_MUST_recognize and act on these declarations and prefixes.
2.3 Comparing URI References
URI references identifying namespaces are compared when determining whether a name belongs to a given namespace, and whether two names belong to the same namespace. [Definition: The two URIs are treated as strings, and they areidenticalif and only if the strings are identical, that is, if they are the same sequence of characters. ] The comparison is case-sensitive, and no %-escaping is done or undone.
A consequence of this is that URI references which are not identical in this sense may resolve to the same resource. Examples include URI references which differ only in case or %-escaping, or which are in external entities which have different base URIs (but note that relative URIs are deprecated as namespace names).
In a namespace declaration, the URI reference is thenormalized valueof the attribute, so replacement of XML character and entity references has already been done before any comparison.
Examples:
The URI references below are all different for the purposes of identifying namespaces, since they differ in case:
http://www.example.org/wine
http://www.Example.org/wine
http://www.example.org/Wine
The URI references below are also all different for the purposes of identifying namespaces:
http://www.example.org/~wilbur
http://www.example.org/%7ewilbur
http://www.example.org/%7Ewilbur
Because of the risk of confusion between URIs that would be equivalent if dereferenced, the use of %-escaped characters in namespace names is strongly discouraged.
3 Declaring Namespaces
[Definition: A namespace(or more precisely, a namespace binding)is**declared** using a family of reserved attributes. Such an attribute's name must either be **xmlns** or begin **xmlns:**. These attributes, like any other XML attributes, may be provided directly or by default. ]
Attribute Names for Namespace Declaration
[1] | NSAttName | ::= | PrefixedAttName | |
---|---|---|---|---|
| DefaultAttName | ||||
[2] | PrefixedAttName | ::= | 'xmlns:' NCName | [NSC: Reserved Prefixes and Namespace Names] |
[3] | DefaultAttName | ::= | 'xmlns' | |
[4] | NCName | ::= | Name - (Char* ':' Char*) | /* An XMLName, minus the ":" */ |
The attribute'snormalized value _MUST_be either a URI reference — the namespace nameidentifying the namespace — or an empty string. 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). Uniform Resource Names [RFC2141] is an example of a syntax that is designed with these goals in mind. 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 PrefixedAttName, then theNCName gives the namespace prefix, used to associate element and attribute names with thenamespace name in the attribute value in the scope of the element to which the declaration is attached. ]
[Definition: If the attribute name matches DefaultAttName, then thenamespace name in the attribute value is that of the default namespacein the scope of the element to which the declaration is attached.] Default namespaces and overriding of declarations are discussed in 6 Applying Namespaces to Elements and Attributes.
An example namespace declaration, which associates the namespace prefix edi with the namespace name http://ecommerce.example.org/schema
:
Though they are not themselves reserved, it is inadvisable to use prefixed names whose LocalPart begins with the letters x, m, l, in any case combination, as these names would be reserved if used without a prefix.
5 Using Qualified Names
In XML documents conforming to this specification, element names are given asqualified names, as follows:
Element Names
[12] | STag | ::= | '<' QName(S Attribute)* S? '>' | [NSC: Prefix Declared] |
---|---|---|---|---|
[13] | ETag | ::= | '</' QName S? '>' | [NSC: Prefix Declared] |
[14] | EmptyElemTag | ::= | '<' QName(S Attribute)* S? '/>' | [NSC: Prefix Declared] |
An example of a qualified name serving as an element name:
Attributes are either namespace declarationsor their names are given asqualified names:
Attribute
[15] | Attribute | ::= | NSAttName Eq AttValue |
---|---|---|---|
| QName Eq AttValue | [NSC: Prefix Declared] | ||
[NSC: No Prefix Undeclaring] | |||
[NSC: Attributes Unique] |
An example of a qualified name serving as an attribute name:
This constraint may lead to operational difficulties in the case where the namespace declaration attribute is provided, not directly in the XMLdocument 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.If correct operation with such applications is required, namespace declarations_MUST_be provided either directly or via default attributes declared in theinternal subset of the DTD.
Element names and attribute names are also given as qualified names when they appear in declarations in the DTD:
Qualified Names in Declarations
| [16] | doctypedecl | ::= | '<!DOCTYPE' S QName (S ExternalID)? S? ('[' (markupdecl| PEReference| S)* ']' S?)? '>' | | | | -------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------- | --- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---- | ----- | | [17] | elementdecl | ::= | '<!ELEMENT' S QName S contentspec S? '>' | | | | [18] | cp | ::= | (QName| choice| seq) ('?' | '*' | '+')? | | [19] | Mixed | ::= | '(' S? '#PCDATA' (S? '|' S? QName)* S? ')*' | | | | | '(' S? '#PCDATA' S? ')' | | | | | | | [20] | AttlistDecl | ::= | '<!ATTLIST' S QName AttDef*S? '>' | | | | [21] | AttDef | ::= | S(QName | NSAttName)S AttType S DefaultDecl | | |
Note that DTD-based validation is not namespace-aware in the following sense: a DTD constrains the elements and attributes that may appear in a document by their uninterpreted names, not by (namespace name, local name) pairs. To validate a document that uses namespaces against a DTD, the same prefixes must be used in the DTD as in the instance. A DTD may however indirectly constrain the namespaces used in a valid document by providing #FIXED
values for attributes that declare namespaces.
6 Applying Namespaces to Elements and Attributes
6.2 Namespace Defaulting
The scope of adefault namespace declaration extends from the beginning of the start-tag in which it appears to the end of the corresponding end-tag, excluding the scope of any inner default namespace declarations. In the case of an empty tag, the scope is the tag itself.
A default namespace declaration applies to all unprefixed element names within its scope. Default namespace declarations do not apply directly to attribute names; the interpretation of unprefixed attributes is determined by the element on which they appear.
If there is a default namespace declaration in scope, theexpanded namecorresponding to an unprefixed element name has the URI of thedefault namespaceas itsnamespace name. If there is no default namespace declaration in scope, the namespace name has no value. The namespace name for an unprefixed attribute name always has no value. In all cases, thelocal name islocal part(which is of course the same as the unprefixed name itself).
FrobnosticationMoved to here.
Cheaper by the Dozen isbn:number1568491379
A larger example of namespace scoping:
Cheaper by the Dozen isbn:number1568491379
This is a funny book!
The attribute value in a default namespace declaration_MAY_be empty. This has the same effect, within the scope of the declaration, of there being no default namespace.
Name | Origin | Description |
Huntsman | Bath, UK |
BitterFuggles
Wonderful hop, light alcohol, good summer beer
Fragile; excessive variance pub to pub
|
6.3 Uniqueness of Attributes
This constraint is equivalent to requiring that no element have two attributes with the same expanded name.
For example, each of the bad
empty-element tags is illegal in the following:
However, each of the following is legal, the second because the default namespace does not apply to attribute names:
7 Conformance of Documents
This specification applies to XML 1.0 documents. To conform to this specification, a document_MUST_be well-formed according to the XML 1.0 specification [XML].
In XML documents which conform to this specification, element and attribute names_MUST_match the production for QNameand MUST_satisfy the "Namespace Constraints". All other tokens in the document which are_REQUIRED, for XML 1.0 well-formedness, to match the XML production for Name _MUST_match this specification's production for NCName.
[Definition: A document is namespace-well-formedif it conforms to this specification. ]
It follows that in a namespace-well-formed document:
- All element and attribute names contain either zero or one colon;
- No entity names, processing instruction targets, or notation names contain any colons.
In addition, a namespace-well-formed document may also be namespace-valid.
[Definition: A namespace-well-formed document is **namespace-valid**if it is valid according to the XML 1.0 specification, and all tokens other than element and attribute names which are_REQUIRED_, for XML 1.0 validity, to match the XML production forNamematch this specification's production forNCName. ]
It follows that in a namespace-valid document:
- No attributes with a declared type ofID, IDREF(S), ENTITY(IES), or NOTATION contain any colons.