XML namespaces - URL or URN?

April 20, 2006

...

In my experience, working with XML Schemas involves a number of uncertainties. One of the things that I have wondered about a few times is what type of URIs to use as namespace identifier. Basically, URIs comes in two flavours: URLs that represent a resource’s location on the network (together with its access method),
and URNs which represent a resource’s unique name.

The only requirement for the XML namespace identifier is that it is globally unique, hence both URLs and URNs fulfil this requirement. However, there have been a tendency to use URLs instead of URNs. I was then wondering on what the criteria for selecting either option would be, so I tried to look for this information on the Internet.

I have not been able to find a definitive conclusion on this, only that the topic has been discussed. For instance, Recommended XML Namespace for Government Organizations gives a number of pros and cons to the two options. Although the document is concerned with US government organisations, some of its arguments also holds for other types of organisations. Furthermore, Use XML namespaces with care presents some guidelines on the subject.
Based on the various rays of light on this subject I have found on the net, I have come up with the following considerations:

  1. Since URNs denote a resource’s unique name, it seems that URNs fit the purpose of being the XML namespace identifier perfectly. On the other hand, there seems to be a semantic mismatch when using an URL, which denotes a network location, as a unique name.
  2. If a URL is used, and additional information about the schema is found at that location, using the URL makes much more sense. If not, users could be fooled to expect find a resource at this location which does not exist.
  3. One hassle with using URNs is that if done correctly, the organisation should apply to IANA for a URN namespace (according to RFC2611) to make sure that the names defined are unique.
  4. Either approach, one has to make sure that the organisation uses a scheme that prevents name collisions within the organisation. It seems to me that this would be somewhat more intuitive and simpler using URLs than URNs.

As I said, I haven’t come to any conclusion in this subject, but right now it seems to me that using URLs is a bit simpler and a bit more practical. So I think that I will stick with that for now. But I will continue to look for insights on this subject.


Profile picture

Written by Vidar Kongsli who is a software professional living in Oslo, Norway. Works as a consultant, system architect and developer at Bredvid. You should follow him on Twitter