Copyright © 2002 W3C® (MIT, INRIA, Keio), All Rights Reserved. W3C liability, trademark, document use, and software licensing rules apply.
The question (see issue qnameAsId-18) that prompted this finding was "are QNames acceptable replacements for URIs as identifiers within specifications?" This finding documents the TAG's opinion on the use of QNames as identifiers.
This document has been developed for discussion by the W3C Technical Architecture Group.
This document is the work of the editor. It is a draft with no official standing. It does not necessarily represent the consensus opinion of the TAG.
Comments may be directed to the W3C TAG mailing list www-tag@w3.org (archive).
Publication of this document by W3C indicates no endorsement by W3C or the W3C Team, or any W3C Members.
1 QNames in XML
1.1 Colons in Other Contexts
2 QNames in Other Specifications
3 Architectural Observations
4 Architectural Recommendations
5 References
Qualified names (QNames) were introduced by [XML Namespaces]. They were defined for element and attribute names (only) and provide a mechanism for concisely identifying a URI/localname pair.
When used solely in element and attribute names, all QNames are identified by the XML processor and can logically be replaced by the URI/localname pair they identify.
At the request of the XML Schema Working Group, the XML Core Working Group is producing an erratum to [XML Namespaces] to clarify the meaning of colons in other contexts.
In particular, this erratum makes it clear that entity names, processing instruction targets, and notation names are not QNames and they may not include any colons. Documents that do not satisfy this constraint are not namespace well-formed. Furthermore, the values of attributes of type ID, IDREF(S), ENTITY(IES), and NOTATION are also forbidden from containing colons. Documents that do not satisfy this constraint are not namespace valid.
A colon that introduces a namespace validity or namespace well-formedness error into a document does not introduce a QName. In other words, the term "identifier" in this finding is not related to XML identifiers of type ID since they cannot be QNames.
Other specifications, starting with [XSLT], have taken QNames and employed them in contexts other than element and attrbiute names. Specifically, QNames have been used in attribute values and element content.
In these contexts, QNames are most often used to identify a particular element type; they are, in principal, using QNames as they were intended.
It's possible that specifications will invent new uses for QNames as well, using them as shortcuts for unique identifiers derived from a URI/localname pair that have no relationship to element or attribute types.
The TAG makes the following observations:
Whatever the architectural ramifications of using QNames as identifiers in contexts other than XML element and attribute names, it is already established practice.
It is simply not practical to suggest that this usage should be forbidden on architectural grounds.
Using QNames in untyped (#PCDATA
or
xs:string
) attribute values or element content places an additional
burden on the processor that was not anticipated by [XML Namespaces].
If QNames are only used in element and attribute names, the processor can fully resolve all of the prefixes as it parses. This gives it the freedom to discard the prefix-to-URI mappings when they go out of scope. A serializer, presented with an object model that conforms to [XML Namespaces] can manufacture new prefixes on the fly. (In practice, users expect most prefixes to be preserved through transformations, so things aren't quite this simple for most developers, but this is still theoretically the case.)
As soon as QNames may appear in element or attribute values, the processor must retain all of the prefix-to-URI mappings (and any API must expose these mappings). This is necessary because some subsequent micro-parser, in the course of examining some content, may encounter a token that it recognizes as a QName and need to find its URI/localname.
QNames in attribute values or element content by
themselves, in other words, in contexts that could be typed as
xs:QName
([XML Datatypes]) in a schema,
could in principal be identified by
the processor.
The TAG recognizes that there are pragmatic reasons why it is desireable to provide the same kind of URI/localname shortcuts that QNames provide for element and attribute names in other contexts. In addition, the practice is already well established. Therefore, the TAG accepts that it is reasonable to use QNames in this way.
The TAG encourages designers to consider the ramifications of their use of QNames carefully. In particular, it makes the following recommendations.
Specifications should not introduce QNames into mixed content or attribute values with untyped string content.
Specifications should not use tokens that are syntactically QNames (that match the QName production) unless they are also semantically QNames.
Specifications describing an XML language must not introduce new namespace declaration or scoping rules.
Element or attribute values that contain a single QName should be
declared with the xs:QName
type.