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

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

From: Andy Davidson <andy_davidson@apple.com>
Date: Thu, 10 Mar 2011 11:07:55 -0800
Cc: "xmlschema-dev@w3.org" <xmlschema-dev@w3.org>
Message-Id: <4D5D5264-E6E4-4CE4-A503-2D5A52BFBB70@apple.com>
To: "Costello, Roger L." <costello@mitre.org>
Just my 2 cents

I work on a very large project with over 100 engineers building clients and services using Java and ObjC.  Most of these engineers are fairly inexperience and are not experts on xml schema. <choice> is very easy for them to understand, "ref" causes lots of confusion and bugs.

We use choice in our request/response definitions. The response is either a "result" or an "error". Switching our interfaces to work this way has dramatically reduced the number of bugs in our system

Please do not remove <choice>

 I am not sure how well it is supported in JAXB/XJC. We do not have any support of "ref" in ObjC code generators. Does libxml run time validate refs correctly?

Andy


On Mar 8, 2011, at 6:36 AM, Costello, Roger L. 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
> 
Received on Thursday, 10 March 2011 19:08:29 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Thursday, 10 March 2011 19:08:29 GMT