XML Namespaces
Home ] Up ] Why XML? ] Domain-Specific MLs ] XML for XML ] XML Parsing ] XML Documents ] [ XML Namespaces ] DTD and XML Schema ] Using Java with XML ]

 

Namespace Syntax
Prefix Binding
Default Namespaces

 

It's often beneficial to include XML from more than one source in an XML document.  If the sources are independent organizations, who never consulted with one another, then the chances are pretty good that two organizations have used the same element name for different things.

For example, consider the book example from earlier:

<?xml version="1.0" encoding="utf-8"?>
<book>
  <title>The World is Flat</title>
  <subtitle>A Brief History of the Twenty-First Century</subtitle>
  <author>Thomas Friedman</author>
  <publisher>Farrar, Straus and Giroux</publisher>
  <date-published>April 30, 2006</date-published>
  <isbn>0374292795</isbn>
  <pages>593</pages>
  <price>30.00</price>
</book>

Now, in an XML application, we wish to combine this with a review XML vocabulary:

<?xml version="1.0" encoding="utf-8"?>
<review>
  <author>Harsh K. Critic</author>
  <date>5 Nov 2006</date>
  <book>A Brief History of the Twenty-First Century</book>
  <comments>
  This book should be read by every American.
  Blah, blah, blah...
  </comments>
</review>

You'll notice that the <book> and <author> elements are used in both vocabularies.  This presents a naming conflict.

For this reason, it's strongly encouraged that, when you develop XML vocabularies that may be used by others, you specify an appropriately unique XML namespace to separate out your vocabulary from others used in the same XML document.  For details, see http://www.w3.org/TR/REC-xml-names/ .

Here are some details...

 
The page was last updated February 19, 2008