4

A XML namespace should be a URI, but it can use any URI scheme, including those that are not URLs.

Then why do all widely used XML namespaces use the http scheme (e.g. http://www.w3.org/XML/1998/namespace), considering that trying to use the URI as an URL by retrieving that document using the HTTP protocol is not guaranteed to do anything useful (and often doesn't)?

I understand the usefulness of DNS domains in namespace names to help guarantee uniqueness. But that doesn't require the http scheme, there could be a separate scheme for that (something like namespace:w3.org/XML/1998/namespace). This would avoid the confusion between URIs and URLs, while maintaining domain-based uniqueness.

2
  • 2
    I'm guessing the answer is "Tradition!" :/ May 29, 2014 at 17:15
  • 1
    @FrustratedWithFormsDesigner Then the real question becomes: “how and why did that tradition start?”
    – svick
    May 29, 2014 at 17:23

2 Answers 2

3

W3C explains their reasoning for using http URIs in the article URNs, Namespaces and Registries. It specifically discusses XML namespaces and a proposed scheme very similar to namespace mentioned in the question.

According to the article, the big advantage of using http is that retrieving the document pointed to by the URI can work and it can provide useful information to both humans and machines.

1
  • A primary highlighted reason listed was, "To benefit from and increase the value of the World Wide Web..." That is extremely self-serving for the W3C and for the W3C alone.
    – stimpy77
    Mar 25, 2015 at 20:33
2

In most cases, I think that it's "because we've always done it that way." If you look at the Namespace spec you'll see that the examples all use HTTP URLs, but do not give a reason.

On the other hand, if you have control over your public-facing web-service, it can be very useful to actually put documentation at the namespace URL. For example, any of the Spring namespaces (eg: http://www.springframework.org/schema/beans/) take you to a page that contains the relevant XML schema documents for each version.

Personally, I prefer using namespaces that begin with urn:x-, followed by the domain name of whatever company I'm working for. That makes it very clear that this is a namespace, and has no other meaning.

3
  • Is there any particular reason for the x- before the company name? May 30, 2014 at 12:39
  • 1
    @PhilPatterson - It denotes an "experimental" namespace: one that doesn't have to be registered with the IANA. See RFC3406 for more information.
    – kdgregory
    May 30, 2014 at 15:17
  • As a side note, several years ago I submitted an enhancement request to Sun to register a "java" namespace that could by used for serialized Java classes. Never got a followup email, and a quick search doesn't show it at the bug database.
    – kdgregory
    May 30, 2014 at 15:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.