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.

4 Responses to Namespace in xml

  1. i always look for laptop reviews on the internet before buying a new one,::

  2. edsheeran says:

    When I originally commented I clicked the -Notify me when new surveys are added- checkbox and already when a comment is added I get four emails with the exact same comment. Will there be in any manner you can remove me from that service? Thanks!

  3. Your blog is one of a kind, i love the way you organize the topics.,`:*~

  4. galfldcpn uiofc fqbqnea ftee rbielfqvlibmjnb

Leave a Reply

Your email address will not be published.