xs:choice problem

Hi,

I have a problem using xs:choice with the same element name but with different
types

exemple :
<xs:element name="E0">
  <xs:sequence>
    <xs:choice minOccurs="0" maxOccurs="unbounded">
      <xs:element name="E1" type="T1"/>
      <xs:element name="E2" type="T2"/>
    </xs:choice>
  </xs:sequence>
</xs:element>
  
T1, T2 and T3 are complexTypes derived from the same type

example:

<xs:complexType name="T0"/>

<xs:complexType name="T1">
  <xs:complexContent>
    <xs:extension base="T0">
      <xs:sequence>
        <xs:element name="A" type="xs:string"/>
      </xs:sequence>
    </xs:extension>
  </xs:complexContent>
</xs:complexType>

<xs:complexType name="T2">
  <xs:complexContent>
    <xs:extension base="T0">
      <xs:sequence>
        <xs:element name="B" type="xs:string"/>
      </xs:sequence>
    </xs:extension>
  </xs:complexContent>
</xs:complexType>

I want to ensure that the E1 element's type is one the two types T1 et T2

I'm using XMLSpy to validate my documents and schemas
the schema is correct but the following instance document do not pass validation.

<E0>
  <E1>
    <A>a string</A>
  </E1> 
</E0>

The validator tells me a <B> tag is expected

Has anybody an idea to explain how this example is processed by the validator,
and if there is another solution to do the same thing. I can't use "xsi:type"
because I'm creating XML Schemas from existing XML documents.

Thanks for your help

Received on Monday, 15 April 2002 06:24:03 UTC