Default Prefix Declaration
The ideas behind the proposal presented here are neither particularly new nor particularly mine. I’ve made the effort to write this down so anyone wishing to refer to ideas in this space can say “Something along the lines of [this posting]” rather than “Something, you know, like, uhm, what we talked about, prefix binding, media-type-based defaulting, that stuff”.
Criticism of XML namespaces as an appropriate mechanism for enabling distributed extensibility for the Web typically targets two issues:
- Syntactic complexity
- API complexity
Of these, the first is arguably the more significant, because the number of authors exceeds the number of developers by a large margin. Accordingly, this proposal attempts to address the first problem, by providing a defaulting mechanism for namespace prefix bindings which covers the 99% case.
3. The proposal
- Define a trivial XML language which provides a means to associate prefixes with namespace names (URIs);
- Invoking from HTML
- Define a link relation
dpdfor use in the (X)HTML header;
- Invoking from XML
- Define a processing instruction
xml-dpdand/or an attribute
xml:dpdfor use at the top of XML documents;
- Defaulting by Media Type
- Implement a registry which maps from media types to a published dpd file;
- Define a precedence, which operates on a per-prefix basis, namely xmlns: >> explicit invocation >> application built-in default >> media-type-based default, and a semantics in terms of namespace information items or appropriate data-model equivalent on the document element.
XML namespaces provide two essentially distinct mechanisms for ‘owning’ names, that is, preventing what would otherwise be a name collision by associating names in some way with some additional distinguishing characteristic:
- By prefixing the name, and binding the prefix to a particular URI;
- 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 a URI is done via a namespace declaration which takes the form of an attribute, and whose impact is scoped to the 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, using patterns to identify the subtrees where particular URIs apply. I’ve borrowed some of his ideas about how to connect documents to prefix binding definitions.
The approach presented here is similar-but-different, in that its primary goal is to enable out-of-band and defaultable associations of namespaces to names with prefixes, with whole-document scope. The advantages 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:
- Prefixed names are more robust in the face of arbitrary cut-and-paste operations;
- Authors are used to them: For example XSLT stylesheets and W3C XML Schema documents almost always use explicit prefixes extensively;
- Prefix binding information can be very simple: just a set of pairs 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.
If this proposal were adopted, and a dpd document for use in HTML 4.01 or XHTML1:
<dpd ns="http://www.w3.org/1999/xhtml"> <pd p="xf" ns="http://www.w3.org/2002/xforms"/> <pd p="svg" ns="http://www.w3.org/2000/svg"/> <pd p="ml" ns="http://www.w3.org/1998/Math/MathML"/> </dpd>
was registered against the
text/html media type, the following would result in a DOM with
body elements in the XHTML namespace and an
input element in the XForms namespace:
<html> <body> <xf:input ref="xyzzy">...</xf:input> </body> </html>