views:

390

answers:

3

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?
+2  A: 

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
Marc Gravell
So that answers whether they are the same. Why is one form preferred for namespace URI versus another?
Jon Trauntvein
The answer is correct, but in my opinion the reason is faulty (or at least misleading) the namespace URI should never be used for anything other than pure identification. Therefore the result of using it as a base URI isn't really relevant.
Joachim Sauer
+4  A: 

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.

Dimitre Novatchev
+2  A: 

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.

kdgregory
not sure why those links are spanning so much text ... when I went in to edit the post, they appeared correct in the preview
kdgregory
@kdgregory: Actually, "retrievability" may not be such a good idea. Recently AFAIK W3C have been complaining of very high web activity reading xml schemas from its site. They recommended that authors keep and reference local copies of the standard schemas.
Dimitre Novatchev
I'm torn on that issue. On the one hand, yes, an application should maintain its schemas internally (ie, I don't believe in using schemaLocation to reference anything externally). On the other, if you are responsible for the data of record, you have to expect people to access that data.
kdgregory
@kdgregory: Ideally there must be some established mechanism to store the standard schemas locally and to periodically (say, just daily) refresh them from the standard source. Also, an uri-resolver will ensure any external reference is served locally. It would be good to have a W3C spec for that.
Dimitre Novatchev
@Sam Hasker: thanks for the edit - could you explain how you modified the text to fix the links? Doing a "View Source" on your edit (#3) and mine (#2) doesn't seem to show a difference.
kdgregory
@kdgregory I changed "[2]: hhttp:" to "[2]: http:", note the double hh in the first.
Sam Hasler