Thursday, October 14, 2004

XML unprefixed attributes and namespaces...

An issue came up today to do with XML attributes and their namespaces. In the application that I maintain I was readin some XML where the attributes did not have namespace prefixes, but the element did, for example;

<ns1:element att1="val" att2="val">textNode</ns1:element>

This was because the person who had constructed it was working on the theory that the attributes would inherit the namespace of the element. The parser I was using, the JDK default which in this case was Crimson, did not agree.

Neither of us knew the correct answer so we starting routing through the XML Schema specification...this did not provide a clear answer. So we started hunting around elsewhere. This is when we found this page;

Namespace Myths Exploded

Apprently, according to the spec, unprefixed attributes are not part of any namespace. In the end we added the required prefix and all was fine. I am pretty much against using the default namespace in any occasion, I prefer to make everything as explicit as possible where XML and namespaces are concerned, and this has solidifed my position.

Maybe this is a more widely known issue, but we'd not heard about it before so I thought I'd post it.

No comments: