Beware of unqualified elements

Usually I do my best to stay away from XML/XSD/Namespace puzzles. But today, I couldn’t escape it, my minimalist-but-yet-effective xml knowledge got challenged. And that’s really not the kind of challenge I like.

Here is the problem. I couldn’t understand why the following XML document does not validate against the given schema.


         
            
               
                   
               
            
         



	Something went wrong.

After some investigations and with some friends’ eyes, we figured out that the elementFormDefault attribute was the cause of our troubles. In the XML document the element is in the “ode” namespace but the XML schema sets the elementFormDefault attribute to unqualified. As Michael Kay put it, it “means that you want locally-declared elements like [reason] to be in no namespace.”

Even if “unqualified” is the default value, in most schemas, elements are qualified and I didn’t pay attention to that detail :/

So how does a valid document look like? One could be:



	Something went wrong.

There is no default namespace, so unqualified elements default to no namespace.

Another valid instance document of that schema may look like:



	Something went wrong.

The xmlns=”" declaration overrides the previous default namespace.

This article discusses in more details the raison d’ĂȘtre of qualified/unqualified elements.

I am still to be convinced that unqualified elements could be useful, but now I know that Axis2 generates schemas with unqualified elements and for now on I will make no assumptions on the value of that attribute!

ps: if you know why the XML names get down-cased by the Google syntax highlighter for Wordpress, drop me a line please.

Post a Comment

Your email is never published nor shared. Required fields are marked *