Wednesday 1 December 2010

Sixth Task - What is the role of namespaces in XML? What benefits does the use of namespaces confer and what problems may be avoided? Give brief examples to illustrate your answers

XML Name spaces provide a method to avoid element name conflicts. In XML without name spaces, element type names and attribute names are unstructured strings using a restricted set of characters, similar to identifies in programming language. This is problematic in a distributed environment like the WWW, because there is no way of guaranteeing the uniqueness of the element type name, i.e. semantically different elements can appear to have equivalent element type names. For example, one XML document may use part elements to describe of books; another may use part elements to describe parts of cars.

<book>
 <part>...</part>
<part>...</part>
</book>
<car>
  <part...</part>
</car>

Since XML recommendation doesn’t allow multiple attributes with a same name in an XML element. The XML name spaces recommendation tries to improve the situation by extending the data model to allow element type names and attribute names to be qualified with a Uniform Resource Identifier (URI). Thus a document that describes parts of cars can use part qualified by one URI; and a document that describes parts of books can use part qualified by another URI as seen in the above example. The role of the URI in a name is purely to allow application to recognize the name. Though their are no guarantees about the resource identified by the URI. The XML name spaces recommendation does not require element type names and attributes names to be qualified names they are also allowed to be non-qualified names.

The XML name spaces recommendation qualifies names with URIs in an indirect way, based on the idea of a prefix. If an element type name or attribute name contains a colon, then the part of the name before a colon is considered as a prefix and the part of the name after a colon  as a local name. A prefix foo refers to the URI specified in the value in the name of the xmlns:foo attribute. For example, all the XML elements which describe books as shown in the example above my have their element type names qualified with the common URI 
 –http://www.books.com/xml. Then the element which describes parts of books i.e. its local name is part will be represented in XML as:<books: part xmlns:books=http://www.books.com/xml>...</books:parts>

No comments:

Post a Comment