13
votes

I have been studying SOAP and WSDL in preparation for implementing a web service. One thing that I have encountered that puzzles me is that some of the URIs that I have seen use a trailing slash such as:

http://www.w3.org/some-namespace/

while other examples that I have studied omit this trailing slash. I really have several questions regarding this:

  • What is the significance of the trailing slash?
  • Is the URI, http://www.w3.org/some-namespace the same as http://www.w3.org/some-namespace/?
  • If they are not the same, how do I decide when one form is warranted versus another?
  • I have read the guidelines given by w3c regarding URI's and these appear to indicate that that URI should be considered equal only if the case-sensitive comparison of the URI strings are considered equal. Is this interpretation correct?
3

3 Answers

10
votes

Yes, the w3c guidelines regarding URI's you have read are correct.

The two namespaces having not equal-strings-uri's are different namespaces. Even capitalization and white-space matters.

A namespace-uri does not mean that issuing a request for it should produce a web-response. Therefore, any reasoning whether it should or shouldn't end with "/" is not too meaningful.

In fact, a namespace-uri may even not satisfy the syntax rules for an URI and it will still serve its purpose for defining a namespace. It is perfectly useful to use a namespace such as, let's say:

"\/^%$#sdhfgds"

as long as it is unique (do note that in no way I am recommending such use :) ). Existing XML processors (such as parsers, XPath or XSLT processors) do not raise any errors when they encounter such namespace.

6
votes

Namespace URIs are simply meant as unique identifiers (here's a link to the rules for comparison). Use of a URI (versus, say "foo") can be traced back (I believe) to the use of URIs in an XML DOCTYPE.

Which is also, I think where the confusion comes regarding the "retrievability" of such URIs. The XML Spec requires that the SYSTEM identifier in a DOCTYPE may be used to retrieve the document's DTD (I link to the Annotated XML Spec, rather than the W3C version, because I believe that Tim Bray's commentary is very useful).

Although other specifications (eg, XML schema) do not require this behavior, I believe that it's a useful habit to follow -- particularly in the case of Schema target namespaces. For one thing, it makes it easy for consumers of your schema to always find the correct definition. For another, if you have the power to put the document at a public URL, then you can also ensure that the URI is unique.

Finally: Uniform Resource Identifiers (URIs) are a superset of Uniform Resource Locators (URLs). You can also have a Uniform Resource Name (URN), and I believe (but don't have the spec handy) that there is a third form of identifier.

3
votes

No they aren't the same.

The biggest difference would be in the forming of relative uris from that base; with the slash, the relative uri would be a descendent; without the slash it would be a sibling - i.e. (C# example):

    Uri uri = new Uri(@"http://www.w3.org/some-namespace/");
    Console.WriteLine(new Uri(uri, "foo")); // http://www.w3.org/some-namespace/foo

    uri = new Uri(@"http://www.w3.org/some-namespace");
    Console.WriteLine(new Uri(uri, "foo")); //http://www.w3.org/foo