Re: all group

Hi Avin,

> What is difference between following 2 schemas:
> 1)
>  <xsd:complexType name="Type1">
>     <xsd:all>
>        <xsd:element name="elem1" type="xsd:integer"/>
>        <xsd:element name="elem2" type="Type2"/>
>    </xsd:all>
>  </xsd:complexType>
>
>  <xsd:complexType name="Type2">
>    <xsd:all>
>         <xsd:element name="elem1" type="xsd:integer"/>
>         <xsd:element name="elem2" type="xsd:boolean"/>
>    </xsd:all>
>  </xsd:complexType>
>
> 2)
>  <xsd:complexType name="Type1">
>     <xsd:all>
>        <xsd:element name="elem1" type="xsd:integer"/>
>        <xsd:element name="elem2" >
>             <xsd:complexType>
>                <xsd:all>
>                    <xsd:element name="elem1" type="xsd:integer"/>
>                    <xsd:element name="elem2" type="xsd:boolean"/>
>                </xsd:all>
>             </xsd:complexType>
>    </xsd:all>
>  </xsd:complexType>

The only difference is that in the former the complex type of elem2 is
named Type2 whereas in the latter the complex type of elem2 is
anonymous. They both state the same set of constraints on the content
of elements of type Type2.

> XML data:
> a)
> Value for Schema definition 1:
>  <Type1>
>     <elem1>3</elem1>
>      <elem2>
>         <Type2>
>             <elem1>4</elem1>
>             <elem2>true</elem2>
>         </Type2>
>      </elem2>
> </Type1>

This XML is invalid against both schemas because both schemas state
that elem2 contains an elem1 element followed by an elem2 element, but
here the elem2 element contains a Type2 element. You seem to think
that named complex types indicate elements in an XML document; this is
not the case.

> b)
> value for Schema definition 2, Can't be applicable to definition 1:
>  <Type1>
>     <elem1>3</elem1>
>      <elem2>
>             <elem1>4</elem1>
>             <elem2>true</elem2>
>       </elem2>
> </Type1>

This XML is valid against both schemas, assuming that the Type1
element is declared with a Type1 type, for example with:

<xs:element name="Type1" type="Type1" />

Cheers,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/

Received on Thursday, 2 January 2003 20:47:27 UTC