Default Prefix Declaration
Henry S. Thompson
18 Nov 2009
Table of Contents
1. Disclaimer
The ideas behind the proposal presented here are neitherparticularly new nor particularly mine. I've made the effort towrite this down so anyone wishing to refer to ideas in this spacecan say "Something along the lines of [this posting]" rather than"Something, you know, like, uhm, what we talked about, prefixbinding, media-type-based defaulting, that stuff".
2. Introduction
Criticism of
XMLnamespaces as an appropriate mechanism for enabling distributedextensibility for the Web typically targets two issues:
- Syntactic complexity
- API complexity
Of these, the first is arguably the more significant, becausethe number of authors exceeds the number of developers by a largemargin. Accordingly, this proposal attempts to address the firstproblem, by providing a defaulting mechanism for namespace prefixbindings which covers the 99% case.
3. The proposal
BindingDefine a trivial XML language which provides a means toassociate prefixes with namespace names (URIs);
Invoking from HTMLDefine a link relation dpd for use in the (X)HTMLheader;
Invokingfrom XMLDefine a processing instruction xml-dpd and/or anattribute xml:dpd for use at the top of XMLdocuments;
Defaulting by Media TypeImplement a registry which maps from media types to a publisheddpd file;
SemanticsDefine a precedence, which operates on a per-prefix basis,namely xmlns: >> explicit invocation >> applicationbuilt-in default >> media-type-based default, and a semanticsin terms of
namespaceinformation items or appropriate data-model equivalent on thedocument element.
4. Whyprefixes?
XML namespaces provide two essentially distinct mechanisms for'owning' names, that is, preventing what would otherwise be a namecollision by associating names in some way with some additionaldistinguishing characteristic:
- By prefixing the name, and binding the prefix to a particularURI;
- By declaring that within a particular subtree,unprefixed names are associated with a particular URI.
In XML namespaces as they stand today, the association with aURI is done via a
namespace declarationwhich takes the form of an attribute, and whose impact is scoped tothe subtree rooted at the owner element of that attribute.
Liam Quin
has proposed an additional, out-of-band and defaultable,approach to the association for
unprefixed names, usingpatterns to identify the subtrees where particular URIs apply. I'veborrowed some of his ideas about how to connect documents to prefixbinding definitions.
The approach presented here is similar-but-different, in that its primarygoal is to enable out-of-band and defaultable associations of namespacesto names
with prefixes, with whole-document scope. Theadvantages of focussing on prefixed names in this way are:
- Ad-hoc extensibility mechanisms typically use prefixes.The HTML5 specification already has at least two of these:aria- and data-;
- Prefixed names are more robust in the face of arbitrarycut-and-paste operations;
- Authors are used to them: For example XSLT stylesheets and W3CXML Schema documents almost always use explicit prefixesextensively;
- Prefix binding information can be very simple: just a set ofpairs of prefix and URI.
Provision is also made for optionally specifying a binding for the default namespace at the document element, primarily for the media type registry case, where it makes sense to associate a primary namespace with a media type.
5. Example
If this proposal were adopted, and a dpd document for use in HTML 4.01 or XHTML1:
was registered against the text/html media type, the following would result in a DOM with html and body elements in the XHTML namespace and an input element in the XForms namespace:
...
More...