[Update: oops, I forgot to give this post a real title.]
Note to self: Whenever I will come up with new XML formats, I’ll put them into XML namespaces. To quote SGML greybeard and XML co-inventor Eliot Kimber:
If you’re not using namespaces you should be–I can’t see any excuse for anyone defining any set of XML elements that is not in a namespace. It should be required and it’s too bad that XML, for compatibility reasons, has to allow no-namespace documents.
That post from Eliot is quite interesting if you’re interested in XML arcana and systems design. It gives some background on why XML namespace URIs don’t have to point to anything (a fact it took me a while to get my head around) – it’s because they don’t have to. That’s just the Way of the Web, as Eliot puts it.
“So why don’t namespaces have this [an object behind an URI]? Simple answer: because they didn’t need them in order to be useful. That’s the beauty of the Web: it’s agile methods at work–the simplest thing that could possibly work.” (Kimber)
I think this gives a hint why people often create XML documents that are not namespace-bound: They don’t need namespaces to be useful in their context. Even further, namespace usage would mean that much XML code would need to be added, like (long) namespace URIs and (many many) prefixes.
Sorry, I forget to identify myself at the preceding comment… :)
David, that’s a good point, and a flaw in his argument that I didn’t notice.
However, even if the format designer didn’t think of this, any XML format may be used in a situation where being in a namespace makes things easier, like sending it as a SOAP payload or doing any nontrivial transformation with XSLT. Using a namespace is a good precaution and good practice.
It also won’t bloat your XML if you use a default namespace declaration. All you have to add is `xmlns=”http://example.com/my-namespace-uri/”` on the root element.