Namespace in xml

Namespace

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″?>

<html>

<body>

<p>My School Information</p>

</body>

 

<body>

<course>Calculus</course>

<grade>A</grade>

</body>

 

</html>

 

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=’http://www.mysite.org/safe/space/’>

<html:body>

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

</html:body>

 

<school:body xmlns:school=’http://www.myschool.edu/grades’>

< school:course>Calculus</course>

< school:grade>A</grade>

</ school:body>

 

</html:html>

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

10 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

  5. ADME Studies says:

    311562 857946Hi my loved 1! I want to say that this article is incredible, wonderful written and consist of almost all vital infos. I would like to peer a lot more posts like this . 458917

  6. ampme pc says:

    I’m impressed, I have to admit. Genuinely rarely should i encounter a weblog that’s both educative and entertaining, and let me tell you, you may have hit the nail about the head. Your idea is outstanding; the problem is an element that insufficient persons are speaking intelligently about. I am delighted we came across this during my look for something with this.

  7. Enjoyed reading through this, very good stuff, thankyou .

  8. very nice post, i actually love this web site, carry on it

  9. 197238 337623I enjoy what you guys are typically up too. This kind of clever work and reporting! Keep up the very excellent works guys Ive added you guys to blogroll. 119991

  10. 424572 872749As I internet site owner I conceive the content material here is rattling excellent , thanks for your efforts. 330841

Leave a Reply

Your email address will not be published.