Re: xs:choice problem

Hi Laurent,

> I have a problem using xs:choice with the same element name but with
> different types
[snip]
> 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.

I'm afraid that you can't use XML Schema to say that an element can
have one of two types without using xsi:type in the instance document
to indicate which of the two types a particular instance element is.

The best you can do is create a type that encompasses both
possibilities, and then use extra processing if necessary (for example
Schematron) to state that only one of the two is possible. In your
example, you could do:

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

and then simply have:

<xs:element name="E0">
  <xs:complexType>
    <xs:sequence>
      <xs:element name="E1" type="T1"
                  minOccurs="0" maxOccurs="unbounded"/>
    </xs:sequence>
  </xs:complexType>
</xs:element>

Cheers,

Jeni

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

Received on Monday, 15 April 2002 07:28:23 UTC