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

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

From: George Cristian Bina <george@oxygenxml.com>
Date: Tue, 08 Mar 2011 16:45:59 +0200
Message-ID: <4D764127.3030307@oxygenxml.com>
To: "Costello, Roger L." <costello@mitre.org>
CC: "xmlschema-dev@w3.org" <xmlschema-dev@w3.org>
Hi Roger,

When you use substitution groups there are additional constraints on the 
type of the elements that can substitute an element while when using 
plain choice there are no such constraints.

Actually the content model when you have substitution groups like in 
your example is a choice between all the elements that can substitute 
that element. This will not work very well I think if you need to 
specify something like

(a, b) | (b, c)

for example, or something more complex along these lines.

Best Regards,
George Cristian Bina
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger

On 3/8/11 4:36 PM, 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 Tuesday, 8 March 2011 14:46:33 UTC

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