Namespace Support

Virtually every XML application that will be shared with the public should include at least a basic level of namespace support. Even if there are no current plans to publish documents in a particular vocabulary to the outside world, it is much simpler to implement namespaces from the ground up than it is to retrofit an existing application with a namespace.

Namespaces affect everything from how the document is validated to how it is transformed (using a stylesheet language such as XSLT). Here are a few namespace issues to consider before selecting a URI and starting work.

Will instance documents need to be validated using a DTD?

If so, some planning of how namespace prefixes will be assigned and incorporated into the DTD is necessary. DTDs are not namespace aware, so strategic use of parameter entities can make modification of prefixes much simpler down the road.

Will markup from this application need to be embedded in other applications?

If so, some thought needs to be given to potential name collisions. The safest approach is to force every element and possibly every attribute from your application to be explicitly qualified with a namespace. This can be done within an XML Schema by setting the elementFormDefault and attributeFormDefault attributes of the schema element to qualified. If you expect to be mixing the vocabulary only at the element level, you should probably leave your attributes unqualified.

Are there legacy XML document formats to support?

If an ...

Get XML in a Nutshell, 3rd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.