Page 1 of 1

Can an XML instance remain valid if its associated schema changes elementFormDefault (unqualified -> qualified)?

Posted: Tue Apr 04, 2017 3:24 pm
by mhGLEIF
I change schema A into new schema B, which is identical to A except that elementFormDefault goes from unqualified -> qualified.

How does an XML instance that was valid per A become valid per B?

Under what circumstances is an XML instance valid under both A and B?

I.e. is the change elementFormDefault (unqualified -> qualified) always (or sometimes) backward compatible?

Re: Can an XML instance remain valid if its associated schema changes elementFormDefault (unqualified -> qualified)?

Posted: Tue Apr 04, 2017 4:01 pm
by Radu
Hi Michael,

The specs can be read here:

https://www.w3.org/TR/xmlschema-0/#ref50

As far as I know the elementFormDefault controls only the default namespace of elements declared locally in the XML Schema.
If the XML Schema has no target namespace attribute set on it, the attribute value should not matter.
Also if you do not have any local declared elements the attribute value should not matter at all.

Let's say we have a simple XML Schema looking like this:

Code: Select all

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
    elementFormDefault="qualified" targetNamespace="testNs">
<xs:element name="a">
    <xs:complexType>
        <xs:sequence>
            <xs:element name="b"/>
        </xs:sequence>
    </xs:complexType>
</xs:element>   
</xs:schema>


It declares a global element named a and a local element named "b". Because you have elementFormDefault="qualified", the declared "b" element is interpreted as being in the testNs namespace so this XML file instance is valid:

Code: Select all

<a xmlns="testNs"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="testNs test.xsd">
    <b></b>
</a>


If you remove the "elementFormDefault="qualified" " from the XML Schema and validate again the XML instance, the validation will complain as it would expect the "b" element to be in no namespace.
So a valid XML instance would look like this:

Code: Select all

<a xmlns="testNs"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="testNs file:/D:/projects/eXml/samples/dita/flowers/test.xsd">
    <b xmlns=""></b>
</a>


Regards,
Radu