Re: Qualification, inheritance and import

Comments inline

----- Original Message -----
From: "Grégoire Pau" <gpau@acland.fr>
To: <www-xml-schema-comments@w3.org>
Sent: Monday, May 07, 2001 6:51 PM
Subject: Qualification, inheritance and import


Dear all,

I am currently having trouble with the combined use of
inheritance and imports. Let's have an example :

 - In namespace ns1 :

   <schema
        xmlns="http://www.w3.org/2000/10/XMLSchema"
        xmlns:ns1="http://www.ns1.com"
        xmlns:ns2="http://www.ns2.com"
        targetNamespace="http://www.ns1.com">

             <element name="A" type="USAddress"/>

             <complexType name="USAddress">
               <complexContent>
                 <sequence>
                  <element name="name"   type="string"/>
                  <element name="street" type="string"/>
                 </sequence>
               </complexContent>
              </complexType>
   </schema>


 - In namespace ns2 :

   <schema
        xmlns="http://www.w3.org/2000/10/XMLSchema"
        xmlns:ns1="http://www.ns1.com"
        xmlns:ns2="http://www.ns2.com"
        targetNamespace="http://www.ns2.com">

            <import namespace="http://www.ns1.com"
                schemaLocation="http://www.ns1.com/ns1.xsd"/>

            <complexType name="Analyst">
              <complexContent>
               <extension base="ns1:USAddress">
                <sequence>
                 <element name="phone" type="string"/>
                </sequence>
               </extension>
              </complexContent>
             </complexType>

            <!-- for later use -->
            <element name="email" type="string"/>
   </schema>


Which one of the following document is valid ?

 - Document 1:

    <ns1:A xsi:type="ns2:Analyst"
                        xmlns:xsi="http://www....."
                        xmlns:ns1="http://www.ns1.com"
                        xmlns:ns2="http://www.ns2.com">
        <ns1:name>John doe</ns1:name>
        <ns1:street>Lacepede</ns1:street>
        <ns2:phone>...</ns2:phone>
    </ns1:A>


 - Document 2:

    <ns1:A xsi:type="ns2:Analyst"
                xmlns:xsi="http://www....."
                xmlns:ns1="http://www.ns1.com"
                xmlns:ns2="http://www.ns2.com">
        <ns2:name>John doe</ns2:name>
        <ns2:street>Lacepede</ns2:street>
        <ns2:phone>...</ns2:phone>
    </ns1:A>


<MJG>
Neither! The following would be valid;

    <ns1:A xsi:type="ns2:Analyst"
                        xmlns:xsi="http://www....."
                        xmlns:ns1="http://www.ns1.com"
                        xmlns:ns2="http://www.ns2.com">
        <name>John doe</name>
        <street>Lacepede</street>
        <phone>...</phone>
    </ns1:A>

Local element declarations are unqualified by default. Put
elementFormDefault='qualified' on the schema element for ns1 and ns2 to make
Document 1 valid.
</MJG>

Then, what about element ref ?

Let's define a new schema in a new namespace :

   <schema
        xmlns="http://www.w3.org/2000/10/XMLSchema"
        xmlns:ns2="http://www.ns2.com"
        xmlns:ns3="http://www.ns3.com"
        targetNamespace="http://www.ns3.com">

            <import namespace="http://www.ns2.com"
                schemaLocation="http://www.ns2.com/ns2.xsd"/>

            <complexType name="ModernAnalyst">
              <complexContent>
               <extension base="ns2:Analyst">
                <sequence>
                 <element ref="ns2:email"/>
                </sequence>
               </extension>
              </complexContent>
             </complexType>
   </schema>

Then which one of the following document is valid ?

    <ns1:A xsi:type="ns3:ModernAnalyst">
                xmlns:xsi="http://www....."
                xmlns:ns1="http://www.ns1.com"
                xmlns:ns2="http://www.ns2.com"
                xmlns:ns3="http://www.ns3.com">
        <??:name>John doe</??:name>
        <??:street>Lacepede</??:street>
        <??:phone>...</??:phone>
        <ns3:email>...</ns3:email>
    </ns1:A>

    <ns1:A xsi:type="ns3:ModernAnalyst">
                xmlns:xsi="http://www....."
                xmlns:ns1="http://www.ns1.com"
                xmlns:ns2="http://www.ns2.com"
                xmlns:ns3="http://www.ns3.com">
        <??:name>John doe</??:name>
        <??:street>Lacepede</??:street>
        <??:phone>...</??:phone>
        <ns2:email>...</ns2:email>
    </ns1:A>

<MJG>
Valid document would be

    <ns1:A xsi:type="ns3:ModernAnalyst">
                xmlns:xsi="http://www....."
                xmlns:ns1="http://www.ns1.com"
                xmlns:ns2="http://www.ns2.com"
                xmlns:ns3="http://www.ns3.com">
        <name>John doe</name>
        <street>Lacepede</street>
        <phone>...</phone>
        <ns2:email>...</ns2:email>
    </ns1:A>

If you put elementFormDefault='qualified' on the schema element for ns1 and
ns2 the following would be valid;

    <ns1:A xsi:type="ns3:ModernAnalyst">
                xmlns:xsi="http://www....."
                xmlns:ns1="http://www.ns1.com"
                xmlns:ns2="http://www.ns2.com"
                xmlns:ns3="http://www.ns3.com">
        <ns1:name>John doe</ns1:name>
        <ns1:street>Lacepede</ns1:street>
        <ns2:phone>...</ns2:phone>
        <ns2:email>...</ns2:email>
    </ns1:A>

Hope this helps,

Martin Gudgin
DevelopMentor
</MJG>

Received on Monday, 7 May 2001 14:27:57 UTC