Search code examples
xmlprogramming-languagesxsd

How to choose the namespace name of a new XML language?


I've created a (domain-specific) language based on XML that I hope will be widely used. To "implement" it I'm using an xsd file.

Until now I've used an url like this as the xml-language namespace :

http://languagemainsite.org/lang/1.0/

Now, I'm not sure it's the best way to choose the namespace, for long term:

  1. Maybe the version number in the namespace is overkill? It's already defined in the "version" attribute too, but I thought it would be nice to have different url per version?
  2. Is it always good to use an url for this?
  3. ????

Any advice about naming namespaces for xml-based language?


Solution

  • If the foo element in the namespace http://languagemainsite.org/lang/1.0/ is semantically a different concept to a foo element in the namespace http://languagemainsite.org/lang/1.1/, the namespaces should be different. If they're not—if a Lang-1.1 foo is just a Lang-1.0 foo maybe with a few extra features—they should be in the same namespace.

    Consider, for example, the <p> element in XHTML 1.0, XHTML 1.1 and XHTML5. It is semantically the same thing (a paragraph) in all versions of XHTML, so they can all live in the http://www.w3.org/1999/xhtml namespace, even though they have different capabilities in the different language versions.

    Including a version number in the namespace makes backwards-compatibility very difficult. Applications supporting two versions of the language would have to switch namespaces to cope with the same named elements, and a version-1-supporting application can't practically read a version-2 document at all.

    So only use versioned namespaces for new ‘major version’ updates that deliberately completely drop backwards compatibility. Otherwise, a version attribute on the root element is generally a better idea.

    And yes, you should use a URL, in order to avoid clashing with others' namespaces. It's polite to put some descriptive information up at the URL you use.