   [web] URNs and XML namespaces -- I feel like I'm taking crazy pills.
  Please help. I just don't understand this.First of all, I understand that, at some point, there became a need to refer to a resource by name instead of by location. Why? I don't know, but I trust there were good reasons. Perhaps there's a certain image out there on the web, or something, and there are a hundred different copies of it out there (and therefore hundreds of different URLs), but since they're all copies of the same image, it becomes useful is some contexts to refer to it by a name rather than by location (plus, locations change). Whatever. I don't understand the reasons, but I'm willing to play along.What I really don't get, though, is why did they have to make the URNs appear exactly like web addresses? Why should a name look anything like an address? Do you know how confusing this concept was for me, as a newcomer, who instantly recognized them as URLs? And now I'm trying to figure out why the URL scheme was co-opted for this URN thing, and I can't think of a reason. I mean, a name can look like anything. It's probably going to be hierarchical, so in some way it's bound to look something like a path, but the fact that some of these URNs even appear to have a protocol, a domain, a port, not to mention a path and query...it just seems like they've gone through great effort to shoe-horn something that doesn't quite fit so that we can all reap the "benefit" of conflating names and locations.And now on to XML namespaces. First of all, I noticed that they use URNs for their namespaces. So, see my rant above. I don't really understand why a C++ or C# style namespace wouldn't suffice (i.e., any token of your choosing).And in order to save lots of typing, I can see that XML allows you to attach a URN-style namespace to a short prefix. But this seems absurd to me for a couple of reasons:1) Why should I type my namespace with each element anyway? Why is there no equivalent to C++'s using keyword? Because without that, I don't really need namespaces at all. I can simply name my elements with a suffix, i.e. bob_table instead of first setting bob to some URN in an xmlns somewhere, and then using bob:table.2) Why use the URN at all if you're just going to convert it to a short prefix and use that henceforth in your document? One might argue that URNs are longer, and more likely to be unique, but if you're going to use prefixes, then those must be unique also, or else you'll end up with naming collisions. So if I'm already using a unique prefix, what is the point of the URN?Please understand that I am not trying to wag my finger at all of the smart people who came up with this stuff. I'm just venting my frustrations as a newcomer. I accept as a given that there is some huge misunderstanding on my part, and I'm hoping someone here can set me straight.   
  I'm not an expert on this, but I think I can clear up some misunderstandings. You should also read the spec.First, URN do not really look like URL. urn:www.agxml.org:schemas:all:2:0 or urn:isbn:0451450523 would be pretty hard to confuse with an URL. (Examples courtesy of Wikipedia)Second, XML namespaces use URI and not URN. Since URI is a superset of URN and URL, you can use an URL for an XML namespace (which many people do - having the URI point to an actual schema is neither required nor forbidden by the spec).About why there's no importing (most likely): Different namespaces might use the same elements or attributes (what the spec calls "markup vocabulary"), so if you were to import conflicting namespaces you could end up with a document where it's unclear (to the software processing the document) whether the element "book" belongs to urn:xyzzy::libraryofcongress or to urn:xyzzy:myschoollibrary. There is also the problem that the URI does not necessarily point to a schema, so it becomes difficult to import something that might not actually exist. You can, however, use XML namespace without a prefix - you have control over which namespace is considered "default" within the scope of each element of the XML decoument. The prefix, according to the spec, is only a placeholder for the actual namespace name. So I guess the point is to make you type less, since URI tend to be long (consisting at least of a scheme, a colon, and a scheme-specific part). Quoteth the spec: "URI references can contain characters not allowed in names, and are often inconveniently long, so expanded names are not used directly to name elements and attributes in XML documents."There's also the point that the prefix might only be unique locally, but the URI is unique universally.[Edited by - lightbringer on May 5, 2009 5:20:56 PM];  Thanks, that gives me quite a bit to think about. I'll have to mull it over a bit, though, before I'm ready to decide whether or not I approve of the internet the way it is. :p   ;  Try XSLT if you haven't already. That's another great way to lose some brain cells. It's like they all got together and tried to make it as convoluted and frustrating as possible.   ;Quote:I don't really understand why a C++ or C# style namespace wouldn't suffice (i.e., any token of your choosing).People could quite easily accidentally pick the same token for something different. URIs and URNs are supposed to be unique. Prefixing the token of your choosing with your domain name is a pretty good way to make sure you're not colliding with someone else's namespace.   ;Quote:Original post by CDPropThanks, that gives me quite a bit to think about. I'll have to mull it over a bit, though, before I'm ready to decide whether or not I approve of the internet the way it is. :pIf you think this stuff is confusing, just try out UDDI or RDF.   ;Quote:Original post by SanderQuote:I don't really understand why a C++ or C# style namespace wouldn't suffice (i.e., any token of your choosing).People could quite easily accidentally pick the same token for something different. URIs and URNs are supposed to be unique. Prefixing the token of your choosing with your domain name is a pretty good way to make sure you're not colliding with someone else's namespace.Yeah, I guess my confusion there was that, if you're going to alias your namespace, in effect, with a short, memorable 'suffix', then you've just gotten rid of all of the benefits of using a long, URL-like name. However, what I did not understand at the time was that a prefix only applies to the element that declared it, as well as nested elements. That makes a whole lot of difference.