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

This should cover W3C XML Schema, Relax NG and DTD related problems.
mhGLEIF
Posts: 40

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

Tue Apr 04, 2017 3:24 pm

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?
Radu
Posts: 5095

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

Tue Apr 04, 2017 4:01 pm

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
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com

Return to “XML Schemas”

Who is online

Users browsing this forum: No registered users and 0 guests