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

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

From: Kevin Braun <kbraun@obj-sys.com>
Date: Tue, 08 Mar 2011 09:46:29 -0500
Message-ID: <4D764145.8050301@obj-sys.com>
To: "Costello, Roger L." <costello@mitre.org>
CC: "xmlschema-dev@w3.org" <xmlschema-dev@w3.org>
As I recall, in order to substitute one element for another (as in 
substitution groups), you have to be using global elements and their 
types must be compatible.  The choice allows for local elements (they 
can be in no namespace) and they can have types that are not at all 
related.  In your example, train, plane, and automobile happen to have 
the same content models, but that may not always be the case.

Kevin

-- 
Objective Systems, Inc.
REAL WORLD ASN.1 AND XML SOLUTIONS
http://www.obj-sys.com



On 3/8/2011 9: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 Tuesday, 8 March 2011 14:47:02 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Tuesday, 8 March 2011 14:47:35 GMT