XML.com: XML From the Inside Out
oreilly.comSafari Bookshelf.Conferences.

advertisement

Namespaces in XML Adopted by W3C

January 19, 1999

The "Namespaces in XML" specification has been formally adopted by the W3C as a recommendation from its members and its director, Tim Berners-Lee, paving the way for vendors to create software that will more easily support the rich markup vocabularies made possible by XML.

What's the problem?
XML is a language for creating markup -- think of it as the way to write down new tag sets that your software will recognize and make use of. The whole point of XML is to enable users to be able to create unique tags that identify their information in more meaningful ways than simply applying the basic set of HTML tags to all documents.

While this gives users great flexibility, it poses problems for interchange and software integration. What happens when two documents make use of the same tag names in different contexts? For example, a <PART> tag in an illustrated parts catalog identifies something quite different than a part in a dramatic play. Within a single document, the term "title" may refer to the document itself, the name of a book, and the formal appellation associated with its author (e.g., "Dr."). The problem is not just for element names; it extends to attributes as well.

This potential collision over different uses of the same names poses problems for anyone writing XML- based software and applications. It?s difficult to write a style sheet that displays book titles in italic but gives no special formatting to people?s titles if I don?t have a good way to distinguish the two uses of the title tag.

A partial solution
The XML namespaces spec addresses this issue by allowing tags to have a context. That context is the tag or attributes? XML namespace, which is simply a Web address. Because Web addresses are unique, they?re a handy way to establish unique contexts. For example, you could create a namespace called EDI, linked to a URL; declare that namespace at the beginning of your XML document; and then add "EDI:" as a prefix to any element name in the document. The use of the declared prefix provides a way for software to treat tags with EDI prefixes differently than tags with different, prefixes. You can also declare a default namespace at the start of your document; any tags without prefixes are assumed to be in the default namespace.

One thing the namespace does not define is what the tags or attributes are, or what they mean. That larger effort, which would enable DTD designers to reference public tag sets, is part of what the XML schema working group is tackling. Further details on how namespaces operate can be seen in our accompanying story, and in the specification itself.

Further information about upcoming developments of XML are available at the W3C Web site.

The implications
All along, it has been envisioned that XML will be applied to specific vertical industries. Medicine has patient records; legal publishing has court cases and commentary; aerospace has its massive engines and planes. Many have presumed that XML wouldn?t take off until vertical industries published their DTDs.

Public DTDs are useful, and ultimately we are likely to see more of them. In the meantime, though, some people writing their own XML applications (software acting on private DTDs) would like a way to at least resolve tag and attribute name conflicts. Knowing the meaning of the tags is required for true interchange, but for the purposes of creating style sheets for display, it may be enough to simply have a unique ID and make an educated guess about the meaning.

"Think of an invoice," suggests Dan Connolly, W3C XML Activity Lead. "Most of an invoice like the addresses and quantities and amounts are in regular commercial language. But maybe the descriptions of exactly what parts have been ordered would only be understood by experts manufacturing or using the parts. Still, many people can understand the invoice without having to understand what the part description means. XML namespaces allows a digitally coded document like this invoice to be processed -- without everyone who uses invoices having to agree on a vocabulary for turbojet engine side intake manifold monitor valve mounting nuts, or whatever."

With the namespace spec, what the W3C has said is that what is required is a standard way to resolve conflicts in tag names, so that programmers around the globe can work from a common understanding of how tags will be identified.

The XML namespace spec does provide this universal mechanism that everyone can use to create tag and attribute names that are unique in the context of specific documents, just as file names are unique in the context of the directory of a computer?s hard disk.

Though namespaces operate "under the hood" and are really aimed at programmers, they will enable a variety of functions -- from interesting typographic treatment of elements to sophisticated processing of orders and invoices -- that all manner of Web users, even novices, will appreciate.

Pages: 1, 2

Next Pagearrow