4
votes

Let us consider this xml data

<root xmlns:h="http://www.w3.org/TR/html4/"
 xmlns:f="http://www.w3schools.com/furniture">

<h:table>
  <h:tr>
    <h:td>Apples</h:td>
    <h:td>Bananas</h:td>
  </h:tr>
</h:table>

<f:table>
  <f:name>African Coffee Table</f:name>
  <f:width>80</f:width>
  <f:length>120</f:length>
</f:table>

</root>

Here NURI for h : "http://www.w3.org/TR/html4/"
NURI for f : "http://www.w3schools.com/furniture"
What does the NURI(Namespace URI) exactly means?. Is it necessary?. What it actually contains?

1
@andrewb Thats fine. I am asking about NURI?Siva Krishna Aleti

1 Answers

3
votes

The use of XML namespaces in your example is necessary because you have two table elements in your document with different meaning. They are not the same. One comes from XHTML, the other from a W3 Schools vocabulary. You distinguish between them by "putting" the first table in the XHTML NS thanks to the local prefix h which is bound to the http://www.w3.org/TR/html4/ NS and the second table in the other NS thanks to the local prefix f which is bound to the http://www.w3schools.com/furniture NS. Now, by building expanded names and comparing URIs, we are able to differentiate between both elements. Note that prefixes are arbitrary.

The namespace URI is what allows us to identify uniquely the namespace. It is also called the namespace name. If you use an URL, you will take advantage of the uniqueness of domain names in the domain name system (DNS).

In Namespaces in XML 1.0 sections 2.1, we can read that:

An XML namespace is identified by a URI reference

And in section 2.3:

URI references identifying namespaces are compared when determining whether a name belongs to a given namespace, and whether two names belong to the same namespace. [Definition: The two URIs are treated as strings, and they are identical if and only if the strings are identical, that is, if they are the same sequence of characters. ] The comparison is case-sensitive, and no %-escaping is done or undone.

That means that when one (a program) has to compare NS URIs it does it only as raw string comparison. The URI doesn't have to be an URL pointing to a resource on the Internet (e.g. a web page accessible through HTTP).

Please note that the URI is used with a local name (name without colon) to build an expanded name i.e. a pair (URI, localName) that you may write as {URI}localName (James Clark notation) and that pair is used instead of local names alone. Both notations are not standard and cannot be used inside an XML document. It simply allows use to write things down. The namespace doesn't exist as such, but the recommendation explains how we use expanded names and how we can use a special attribute named xmlns to build such expanded names. That's it, no more, no less.

Let me suggest that your read Namespace Myths Exploded by Ronald Bourret.

Namespaces in XML 1.1 generalizes the usage of URIs to IRIs.