XML Namespaces

Name Conflicts: XML Namespaces provide a method to avoid element name conflicts.

In XML, element names are defined by the developer. This often results in a conflict when trying to mix XML documents from different XML applications.

This XML carries HTML Book information (Index details):

<book>
  <index>
    <chapter>second</chapter>
    <page>thirty</page>
  </index>
</book>

This XML carries information about a Book (price details):

<book>
  <author>African Coffee Table</author>
  <price>90</price>
  <publisher>INX</publisher>
</book>

If these XML fragments were added together, there would be a name conflict. Both contain a <book> element, but the elements have different content and meaning.

An XML parser will not know how to handle these differences.

This Name Conflict can Solve by Using a Prefix

Name conflicts in XML can easily be avoided using a name prefix. This XML carries information about an HTML book, and a price details:

<x:book>
  <x:index>
    <x:chapter>second</x:chapter>
    <x:page>thirty</x:page>
  </x:index>
</x:book>

<y:book>
  <y:author>African Coffee Table</y:author>
  <y:price>90</y:price>
  <y:publisher>INX</y:publisher>
</y:book>

In the example above, there will be no conflict because the two <book> elements have different names.

  © Blogger templates The Professional Template by Ourblogtemplates.com 2008

Back to TOP