Handling Namespaces

Namespaces are a mechanism by which similar tags from different DTDs can be used in the same XML document. For example, let's say you create an XML document listing the description of a car, and suppose you have two stereo brands and their price.

The XML document will look like this:

<?xml version='1.0'?>
<car>
    <color>red</color>
    <stereo>
        <brandname>xxxxxx</brandname>
        <price>200</price>
    </stereo>
    <stereo>
        <brandname>yyy</brandname>
        <price>1200</price>
    </stereo>
</car>

Now assume that the price has two different definitions on how it should be processed. This can occur if the stereo vendors are different. In such a case, although the element name is the same, the two price elements belong to different definitions. To allow ...

Get Java™ APIs for XML Kick Start 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.