45

Take this line as just one example:

<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
</configuration>

Some brief research has taught me that nothing necessarily has to be hosted at that URL. Therefore, if it's just a reference to a namespace contained in a local assembly, why use URLs instead of regular namespaces like the ones typically used by .NET (System.Data, for example)?

2
  • 2
    Probably because they are quite unique. Apr 22, 2011 at 17:17
  • 1
    I understand that URLs are for uniqueness. Why exactly do we need unique XML tags? Oct 24, 2013 at 3:06

4 Answers 4

20

When you ask why a standard is the way it is, there are two possible interpretations of your question: (a) what are the perceived benefits of the design choice that was made, and (b) what was the historical sequence of events that led to this design being adopted over other designs.

Clearly, using HTTP-like URIs gives uniqueness. But that could also have been achieved in other ways, for example by inventing a new URI scheme. I think that if you trace the arguments that were made at the time, you will find that many of the people advocating the use of HTTP-style URIs were also advocating that namespace URIs should be dereferencable, perhaps to a schema or to some other kind of document. Indeed, it's W3C policy for its own namespaces that there is always a document that can be retrieved when you type the namespace URI into a browser, and that it should tell you something useful about the namespace.

So I suspect the fact that we use URIs that look deferenceable but don't define any semantics for what happens when they are dereferenced is in fact the result a committee compromise between two or more opposing camps. But you'd have to do some proper historical research to confirm that.

3
  • The explanation sounds entirely plausible to me (smart person, knows next to nothing about XML - just learning now). But it would make a lot more sense if something along these lines were explained in courses, tutorials etc. I see a lot of namespaces that instead of using their authors' private URIs, all point to the w3c site(s) instead - because people blindly copy examples they see somewhere, if they don't understand what they are doing and why. So the uniqueness goes out the window.
    – user5683823
    Sep 20, 2021 at 0:09
  • I'm afraid copying examples without understanding them is the way cool kids do programming these days, and you can write all the books and tutorials in the world and it won't help. Sep 20, 2021 at 8:16
  • I really wish preserving schema URIs as valid web pages were standard practice. Would it really be that hard for someone like Microsoft to make sure schemas.microsoft.com/XML-Document-Transform isn't a dead URL? Feb 17, 2022 at 22:20
13

It's just a convention. URIs (which is what they are, not really URLs) are a convenient and globally-familiar way of identifying resources. On the other hand, .NET-style identifiers are familiar and recognisable to, well, .NET developers - there's rather more to XML than .NET.

10
  • 2
    @Robert: I disagree. XML Namespace URIs need only be unique in the context in which they are used. Ideally, beyond that, yes, but only for public schema.
    – skaffman
    Apr 22, 2011 at 17:33
  • 6
    @oscilatingcretin: The namespace is an arbitrary identifier. You can put anything you want in there ("Grabblesnackers"), but using a URI is done by convention, presumably because it is guaranteed to be unique if you control the domain. Apr 22, 2011 at 17:38
  • 3
    @oscilatingcretin: Schemas.Microsoft.XmlDocumentTransform is still a URI, and is just as valid as anything else. The wider convention, however, is to use URL-style URIs - it's just a convention.
    – skaffman
    Apr 22, 2011 at 17:43
  • 7
    Alright. Deleted last comment, so I apologize to anyone who's still responding to it. So it's basically all arbitrary. Someone with a big wig said, "We're going to prefix our URIs with http even though hypertext transfer protocol isn't even part of the equation. There's not necessarily any rhyme or reason to it, but I have the big wig here and so we're going to go ahead and prefix it with http. Why http and not ftp? Well, because I said so." So that's my take on things. Thanks for the discussion, guys. Apr 22, 2011 at 17:56
  • 5
    Here's a good article why XML namespaces are URIs, and why it was a mistake: xml.com/pub/a/2005/04/13/namespace-uris.html
    – Mas
    Aug 10, 2011 at 8:45
5

W3 explanation Here

Just like namespaces in .NET, namespaces in XML documents are designed to help prevent and resolve name collisions, especially if XML documents are from different organizations and/or domains of knowledge.

XML document format has been stylized by the same people responsible for HTML, so you may find syntactical similarities in elements of the format. Semantically, the dotNET and XML namespaces serve the same goal.

5
  • I understand the concepts of URIs and XML document formatting. My initial post addressed the question of why XML namespaces look like URLs. Yes, I know that a URL is a URI, but there is something distinctly recognizable about a URL. It has a protocol, a domain, a suffix, folder references, and, most of the time, a document. It has been made clear to me that the XML namespace format is what it is simply because original XML ganstas made a decision based on their understanding of how things would work at the time. If XML were invented today, its namespaces would most likely not look like a URL. Apr 23, 2011 at 1:07
  • 3
    Also, several people here have said that URL-style namespaces give uniqueness, but I don't see how. There is no uniqueness guarantee for any URI format, be it an XML- or .NET-style namespace (unless you're talking about a URL). Throwing "http" and ".com" into a namespace just doesn't have any logical backing in my opinion. What if someone failes to renew the domain name registration and someone else buys it (ahem Microsoft)? What good is their URL-style URI now? No consistency, imo. Apr 23, 2011 at 1:13
  • 1
    @oscilatingcretin: GUIDs aren't guaranteed to be unique either, but the likelihood of a properly generated GUID being identical to another is vanishingly small. Using URLs provides a reasonable assurance of uniqueness. May 5, 2011 at 15:53
  • 2
    Reasonable in what way? No one has yet addressed my question of why a URL-style namespace makes sense. What does HTTP (hypertext transfer protocol) have to do with it? Why not FTP? Someone tell me why http:// schemas.microsoft.com/XML-Document-Transform makes sense over Microsoft.Schemas.XmlDocumentTransform. I know I have chosen an answer long ago, but I am all about further discussion on this topic May 5, 2011 at 23:27
  • 4
    I know this is old, but no one answered @oscilatingcretin. The assumption is that microsoft.com is owned by Microsoft and hence "controllable" in a sense. Not perfect by any means, but Microsoft and only Microsoft can publish a schema to microsoft.com/xyz. Unless they forget to renew the domain, etc... :) Jul 16, 2013 at 13:16
3

The core of the problem is that namespaces have to be URIs. There is no good reason for such a thing since all it needs to be is a unique identifier to give context for the defined elements.

Since they have to be URIs, all possibilities are senseless, because a scheme is needed (e.g. http) even though a namespace has nothing to do with such a thing.

So to answer the question of why: like all bad ideas, someone thought it was a good idea at the time.

Your Answer

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

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