W3C home > Mailing lists > Public > xmlschema-dev@w3.org > March 2011

Re: What is lost if xsd:choice is jettisoned?

From: Mukul Gandhi <gandhi.mukul@gmail.com>
Date: Wed, 9 Mar 2011 09:42:47 +0530
Message-ID: <AANLkTikZHamCQOoKa2Jr_9ZiA42Tw-MPK-6wbZ9uwoAZ@mail.gmail.com>
To: "Costello, Roger L." <costello@mitre.org>
Cc: "xmlschema-dev@w3.org" <xmlschema-dev@w3.org>
Hi Roger,
    In your 2nd example using substitutionGroup, the schema as a side
effect would also allow following documents as valid.





(i.e your 2nd schema would also allow above elements as top most
element of the XML document)

But it looks like that your intention is to have a schema for
following document structure,



Therefore if you want to avoid the above side effect [1], the example
using choice would be more appropriate.

On Tue, Mar 8, 2011 at 8:06 PM, Costello, Roger L. <costello@mitre.org> wrote:
> Hi Folks,
> Here is an example of using xsd:choice. The content of <transportation> is a choice of either <train>, <plane>, or <automobile>.
>    <xsd:element name="transportation">
>        <xsd:complexType>
>            <xsd:choice>
>                <xsd:element name="train" type="xsd:string"/>
>                <xsd:element name="plane" type="xsd:string"/>
>                <xsd:element name="automobile" type="xsd:string"/>
>            </xsd:choice>
>        </xsd:complexType>
>    </xsd:element>
> Rather than using xsd:choice, the schema could be designed using xsd:sequence. The sequence consists of an element that ref's to an abstract mode-of-transportation element. The train, plane, and automobile elements are globally declared and are substitutable with mode-of-transportation.
>    <xsd:element name="transportation">
>        <xsd:complexType>
>            <xsd:sequence>
>                <xsd:element ref="mode-of-transportation" />
>            </xsd:sequence>
>        </xsd:complexType>
>    </xsd:element>
>    <xsd:element name="mode-of-transportation" abstract="true" type="xsd:string" />
>    <xsd:element name="train" substitutionGroup="mode-of-transportation"/>
>    <xsd:element name="plane" substitutionGroup="mode-of-transportation"/>
>    <xsd:element name="automobile" substitutionGroup="mode-of-transportation"/>
> I believe that the two designs produce identical results.
> Suppose the xsd:choice element were jettisoned from the XML Schema specification. Would there be any loss of functionality? Put another way, can you provide a real-world, compelling example of a schema that uses xsd:choice which cannot be expressed using abstract element plus substitution groups?
> /Roger

Mukul Gandhi
Received on Wednesday, 9 March 2011 04:14:59 UTC

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