Saturday, April 2, 2011

XML Namespaces

Among the few robust markup languages designed, XML includes to be a language which can be used in various ways and for many different applications. However, with more and more usage of XML in many different platforms it has encountered with one problem that tends to occur with majority of problems in namespace. At such juncture, XML namespaces comes into picture. Now what are XML namespaces and what are its uses. XML Namespaces are methods and ideas which are used to avoid element name conflicts which tend to create problems. Thus they play a pivotal role in rendering uniquely named elements and attributes in an XML document.

Now how is the XML Namespaces defined, they are defined in a W3C recommendation. An XML instance may comprise of attribute or element names from more than one XML vocabulary. So with such case, if each vocabulary is given a namespace then the ambiguity between identically named elements or attributes can be resolved. A simple example can be if you consider an XML instance that contained references to a customer and an ordered product. Both the product element and the customer element could have a next generation id or in other words child element named id. So putting their references to these id elements can be confusing and perplexing, thus the need of placing them in with different namespace can avoid this confusion and thus remove the ambiguity.

Now what are these namespace called? These namespace are commonly known as uniform resource identifier which is usually denoted as URI. Generally, these URI chosen for the namespace of a given XML vocabulary defines a resource under the control of the designer or author or the organization defining the vocabulary, such as a URL for the author's Web server. However, the namespace specification does not require nor suggest that the namespace URI be used to retrieve information; it is simply treated by an XML parser as a string. For example, the document at http://www.w3.org/1999/xhtml itself does not contain any code. It simply describes the XHTML namespace to human readers. Using a URI (generally the links like "http://www.w3.org/1999/xhtml") to identify a namespace, rather than a simple string (such as "XHTML"), reduces the prospects of diverse namespaces using duplicate identifiers.

However, this very term of XML Namespace is quiet popular, and commonly used, the W3C Recommendation refers to it as the namespace name. The specification is not entirely prescriptive about the precise rules for namespace names (as it does not explicitly say or define that parsers must reject documents where the namespace name is not a valid Uniform Resource Identifier), and many XML parsers allow any character string to be used. In version 1.1 of the reference, the namespace name becomes an Internationalized Resource Identifier, which licenses the use of non-ASCII characters that in practice were already accepted by nearly all XML software. The term namespace URI persists, however, not only in popular usage but also in many other stipulations from W3C and elsewhere.

After the publication of the Namespaces recommendation, we saw an extensive and intensive debate about how a relative URI should be used and handled, with some arguing that it should simply be treated as a character string, and others argue that it should be turned into an absolute URI by resolving it against the base URI of the document. The result of the debate was a ruling from W3C that relative URIs were deprecated to the masses.

The use of URIs taking the form of URLs in the http format (such as http://www.w3.org/1999/xhtml) is popular, despite the absence of any formal relationship with the HTTP protocol. The Namespaces specification does not say what should happen or work if such a URL comes with dereferences which means, if the software attempts to retrieve a document from this location. One method or convention adopted by some users is to place a RDDL document at the location. So in other words generally speaking, the users should assume that the namespace URI is simply a name, not the address of a document on the web.

After all the above discussion about the XML namespace, the question arises is to how actually this markup language is used or applied. XML namespaces is a special type of reserved XML attribute that you place in an XML tag. The reserved attribute is actually more like a prefix that you attach to any namespace you create. This attribute prefix is "XMLNS:", which stands for XML namespace. The colon is used to separate the prefix from your namespace that you are creating. The following are the methods of writing XML namespace.

XML Code:


<? xml version="1.0" encoding="ISO-8859-15"?>
<html:html xmlns:html='http://www.w3.org/TR/xhtml1/'>
<html:body>
<html:p>Welcome to my Health Resource</html:p>
</html:body>
<health:body xmlns:health='http://www.example.org/health'>
<health:height>6ft</height>
<health:weight>155 lbs</weight>
</health:body>
</html:html>



So by using a XML Namespace you can actually avert all the issues related to attribute naming and the overlapping problem. So don’t feel inquisitive, just feel free to check them out the W3C's Namespace Document for a very in-depth look at XML namespaces and enjoy hassle free applications.

Popular Posts

Google SEO NEWS: Despite frequent updates, SEO and Google's core search algorithm haven't changed all that much in the past decade. 

Tips and Tricks :  Learn tips and shortcuts to help you work faster. Tips and tricks for getting the most out of your Electronics modules

Health Blog : Posts full of healthy tips & nutritional facts. you'll discover new, interesting health info to assist your health journey.