Every now and then someone thinks about namespaces and nearly everyone seems to be at least slightly confused afterwards. David Magginson tries to clarify on that, although he admits the decision the Namespace group has taken is not really perfect.
Now what really bugs me is that according to his post (and Dare Obasanjo has written about that before too) there are three cases for the namespace of an attribute:
- It’s in the empty (“NULL”) namespace as in
<foo xmlns:empty="" empty:bar="5"/>
- It’s in some namespace
<foo xmlns:a="mynamespace" a:bar="5"/>
- It’s “locally scoped to the element” as in
<foo bar="5"/>, probably the most common case
The annyoing thing about that is in my opinion the “locally scoped” case. I might miss something, but I don’t see any other XML standard that really requires or uses that “locally scoped” feature. At least XPath, XQuery etc. don’t use it, and XML Schema as far as I know doesn’t too, does it?
The namespace should have been either inherited from the element the attribute is in or (in my opinion clearer) been the default namespace set with
<myelem xmlns=“foo”/>. There should really not be any difference between elements and attributes regarding XML namespaces as both use the same syntax (QNames). Using the inherit-mechanism not only for attributes but for elements also might bring strange effects when including XML snippets within other documents.
Another solution would be to forbid elements without explicit namespace prefixes altogether. This would bring some annyoance to users who do not use XML namespaces or just use one within one document, but it would also be absolutely clear. I would prefer to have a clear syntax instead of surprising effects when using namespaces …