Namespace in xml


Since XML is able to communicate between several different platforms, overlapping of elements tends to be a problem that occurs from time to time.  Basically, when the writer has the freedom to create elements, there is a chance that the name used already exists for another element.  Take the example below where an XML document is being created that includes HTML and there are two different elements for “body”.

Example: <?xml version=”1.0″ encoding=”ISO-8859-15″?>



<p>My School Information</p>










This problem can be solved by using an XML namespace to make a distinction between the two elements.  A namespace is a special attribute that can be placed in an XML tag or prefix: “xmlns:”  Like all other attributes, this attribute must be set to some value and that value cannot be the same as any other namespace in the document.  The item commonly used here is a Uniform Resource Identifier (URI) or a URL.   The example below shows how this is done.  In the example, the namespace attribute and its use is highlighted in red.

Example: <?xml version=”1.0″ encoding=”ISO-8859-15″?>

<html:html xmlns:html=’’>


<html:p>My School Information</html:p>



<school:body xmlns:school=’’>

< school:course>Calculus</course>

< school:grade>A</grade>

</ school:body>



This entry was posted in XML Tutorial. Bookmark the permalink.

Leave a Reply

Your email address will not be published.