W3C home > Mailing lists > Public > xmlschema-dev@w3.org > April 2002

Re: xs:choice problem

From: Jeni Tennison <jeni@jenitennison.com>
Date: Mon, 15 Apr 2002 11:42:31 +0100
Message-ID: <1841134529006.20020415114231@jenitennison.com>
To: "Laurent Chaply" <lchaply@imrglobal.fr>
CC: xmlschema-dev@w3.org
Hi Laurent,

> I have a problem using xs:choice with the same element name but with
> different types
> 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:extension base="T0">
        <xs:element name="A" type="xs:string"/>
        <xs:element name="B" type="xs:string"/>

and then simply have:

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



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

This archive was generated by hypermail 2.3.1 : Wednesday, 7 January 2015 14:55:56 UTC