- 96 -
Both are legitimate ways of representing information. Both structures can be defined in a
DTD. But how does one differentiate between these book types? This example is
intentionally scaled down, but you can easily imagine what much more complicated real-
life situations could be. For example, when the same attribute name is used in a single
document with many elements:
Furthermore, when you decide to do special formatting on the book’s name, how do you
distinguish it from the reviewer name attribute? Things can get pretty nasty very quickly,
but lest you think we’re evil people for making you read this entire chapter only to tell you
that an insurmountable obstacle prevents you from making a real-world XML application,
rest assured! There is a solution.
Fortunately, the good people at the W3C have been giving a lot of thought to this
situation. The solution they recommend was finalized in January 1999 and is expressed
in the concept of
namespaces
. Namespaces are a way of uniquely qualifying element
and attribute names on the Web, thus avoiding conflicts between elements (and
attributes) that have the same name.
The idea is to declare a namespace and a corresponding prefix for each DTD or schema
(see the section
“Concluding Thoughts on DTDs”
) and to preface every element or
attribute that is from a particular DTD with its corresponding namespace prefix.
We see the look of consternation on your face, which means its time for another
example. In this one, we’ve combined the information from both our vendors: