Namespaces as opportunity

Namespaces in XML is one of the greatest disasters that XML's creators have inflicted upon XML. Namespaces are complicating for two reasons. First, the declarations for namespaces are made using scoped attribute values, making it much more difficult to move content from one part of a document to another while remaining certain that the labels remain the same. Second, namespaces use URIs as identifiers, a much more complicated set of identifiers than the simple names used on XML 1.0 elements and attributes, laden with the baggage of years of expectations for URLs that have never been standardized for their usage in XML.

Although the specifications have made little effort to contain the damage, these complexity issues can be controlled and namespaces can be a useful part of XML practice. Namespaces offer the chance to identify vocabularies with a label that offers additional information or tools for processing. Rather than treating the URI as an abstraction, you can embrace its concrete value as a locator. The Resource Directory Description Language (RDDL) provides an XML-based standard for such descriptions.

There are also several approaches to handling the scoping issue. Perhaps the most common approach is to put all namespace declarations that will be used in a document in the root element of the document, providing a single point of reference. An alternative approach puts namespace declarations as close to the elements and attributes that use them as possible. This creates a messy-looking document, but may be appropriate for occasional inclusions of elements from foreign namespaces.

Another nit in the specification leads to ambiguity about how to handle unprefixed attributes. The specification states "Note that default namespaces do not apply directly to attributes," but fails to provide further guidance, leaving unqualified attributes in no namespace at all. While there are a number of approaches to dealing with this situation, the safest approach is most likely for applications and vocabularies to treat unqualified attributes as being in the namespace of the element that contains them, prefixed or not. As attributes are metadata for their elements, this approach seems consistent. In general, mixing qualified and unqualified content (something the W3C XML Schema specification defines and SOAP uses) is a poor idea, substantially complicating the disambiguation that Namespaces in XML was supposed to accomplish.

Namespaces have led to the creation of another whole set of problems: namespace-qualified names (QNames) used as attribute or element content. The W3C XML Schema specification blesses this unfortunate practice, which drives the ambiguity and scoping problems of namespaces into content as well as into labels. XML 1.0 parsers have no mechanisms for understanding QNames on their own, and only higher levels of applications will have a chance of figuring out what QNames mean.

Monastic XML Copyright 2002 Simon St.Laurent.