Namespaces in XML 1.1 (original) (raw)
2 XML Namespaces
2.1 Basic Concepts
[Definition: An **XML namespace** is identified by an IRI reference; 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 an IRI I, 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 IRI namespace with the vocabulary's local names that is effective in avoiding name clashes.
IRI 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 IRI References
IRI 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 IRIs 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 IRI references which are not identical in this sense may resolve to the same resource. Examples include IRI references which differ only in case or %-escaping, or which are in external entities which have different base URIs (but note that relative IRIs are deprecated as namespace names).
In a namespace declaration, the IRI reference is thenormalized valueof the attribute, so replacement of XML character and entity references has already been done before any comparison.
Examples:
The IRI 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 IRI references below are also all different for the purposes of identifying namespaces:
http://www.example.org/rosé
http://www.example.org/ros%c3%a9
http://www.example.org/ros%c3%A9
http://www.example.org/ros%C3%a9
http://www.example.org/ros%C3%A9
As are these:
http://www.example.org/~wilbur
http://www.example.org/%7ewilbur
http://www.example.org/%7Ewilbur
If the entity eacute has been defined to be é, the start tags below all contain namespace declarations binding the prefix pto the same IRI reference, http://example.org/rosé
.
<p:foo xmlns:p="http://example.org/rosé">
<p:foo xmlns:p="http://example.org/rosé">
<p:foo xmlns:p="http://example.org/rosé">
<p:foo xmlns:p="http://example.org/rosé">
<p:foo xmlns:p="http://example.org/rosé">
Because of the risk of confusion between IRIs 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 | ::= | NCNameStartChar NCNameChar* | /* An XMLName, minus the ":" */ |
[5] | NCNameChar | ::= | NameChar- ':' | |
[5a] | NCNameStartChar | ::= | NameStartChar- ':' |
The attribute'snormalized value _MUST_be either an IRI 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
[9] | STag | ::= | '<' QName(S Attribute)* S? '>' | [NSC: Prefix Declared] |
---|---|---|---|---|
[10] | ETag | ::= | '</' QName S? '>' | [NSC: Prefix Declared] |
[11] | 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
[12] | Attribute | ::= | NSAttName Eq AttValue |
---|---|---|---|
| QName Eq AttValue | [NSC: Prefix Declared] |
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
| [13] | doctypedecl | ::= | '<!DOCTYPE' S QName (S ExternalID)? S? ('[' (markupdecl| PEReference| S)* ']' S?)? '>' | | | | ------------------------------------------------------------------------------------------------------------------------------------------------------ | ----------- | --- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---- | ----- | | [14] | elementdecl | ::= | '<!ELEMENT' S QName S contentspec S? '>' | | | | [15] | cp | ::= | (QName| choice| seq) ('?' | '*' | '+')? | | [16] | Mixed | ::= | '(' S? '#PCDATA' (S? '|' S? QName)* S? ')*' | | | | | '(' S? '#PCDATA' S? ')' | | | | | | | [17] | AttlistDecl | ::= | '<!ATTLIST' S QName AttDef*S? '>' | | | | [18] | 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 IRI 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
|
7 Conformance of Documents
This specification applies to XML 1.1 documents. To conform to this specification, a document_MUST_be well-formed according to the XML 1.1 specification [XML 1.1].
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.1 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.1 specification, and all tokens other than element and attribute names which are_REQUIRED_, for XML 1.1 validity, to match the XML production forName, match 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.
9 Internationalized Resource Identifiers (IRIs)
Work is currently in progress to produce an RFC defining Internationalized Resource Identifiers (IRIs). Since this work is not yet complete, this section gives a syntactic definition of IRIs for the purposes of this specification. The XML Core Working Group expects to issue an erratum replacing this section with a reference to the RFC when it is published.
Users defining namespaces are advised to restrict namespace names to URIs until the RFC is published and software supporting IRIs is in common use. Implementors are likewise advised not to reject namespace names that violate the drafts in terms of the allowed characters.
For a more general definition and discussion of IRIs see[IRI draft 5] (work in progress).
URI references are restricted to a subset of the ASCII characters; IRI references allow most Unicode characters from #xA0 onwards. Earlier drafts of the IRI RFC (eg [IRI draft 3]) also allowed some of the disallowed ASCII characters, but the current draft ([IRI draft 5]) does not.
[Definition: The additional characters allowed in IRIs by [IRI draft 5]are: ]
- the Unicode plane 0 characters #xA0 - #xD7FF, #xF900-#xFDCF, #xFDF0-#xFFEF
- the Unicode plane 1-14 characters #x10000-#x1FFFD ... #xD0000-#xDFFFD, #xE1000-#xEFFFD
[Definition: An IRI reference is a string that can be converted to a URI reference by applying the following steps: ]
- Convert the hostname part, if present, using the ToASCII operation specified in Section 4.1 of[RFC3490] with the flags UseSTD3ASCIIRules and AllowUnassigned set to TRUE.
- Escape all additional characters as follows:
- Each additional character is converted to UTF-8[RFC3629] as one or more bytes.
- The resulting bytes are escaped with the URI escaping mechanism (that is, converted to %HH, where HH is the hexadecimal notation of the byte value).
- The original character is replaced by the resulting character sequence.
Note:
The algorithm in [IRI draft 5] includes a UCS normalization step, but this makes no difference to which strings are IRI references.