Web Technologies - Old Questions

9.  What are the benefits and drawbacks of using XML name space?

5 marks | Asked in 2068-II

XML Namespace is a mechanism to avoid name conflicts by differentiating elements or attributes within an XML document that may have identical names, but different definitions.

Consider two XML fragment:

//1.xml

<table>

  <tr>

    <td>Apples</td>

    <td>Bananas</td>

  </tr>

</table>

//2.xml

<table>

  <name>African Coffee Table</name>

  <width>80</width>

  <length>120</length>

</table>

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

Name conflicts in XML can easily be avoided using a name prefix.

E.g.

<h:table>

  <h:tr>

    <h:td>Apples</h:td>

    <h:td>Bananas</h:td>

  </h:tr>

</h:table>

<f:table>

  <f:name>African Coffee Table</f:name>

  <f:width>80</f:width>

  <f:length>120</f:length>

</f:table>

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

Advantages
  • It helps us avoid real name clashes with other XML vocabularies.
  • Moreover, namespaces may be used, if XML documents will be distributed to others, when name collisions may really become an issue.
Disadvantages
  • Namespaces, increases the size of XML documents.
  • With namespaces, we need to be extra careful while writing applications (all our programming expressions, querying & creating the XML nodes must be namespace aware). This namespace-awareness overhead (effort to create, and maintain) should be incurred, only if an application requires it (i.e, if management of name collisions is really needed).