W3C home > Mailing lists > Public > xmlschema-dev@w3.org > May 2009

Re: Alternative tags in element?

From: G. Ken Holman <gkholman@CraneSoftwrights.com>
Date: Sat, 02 May 2009 22:20:29 -0400
Message-Id: <>
To: "xmlschema-dev@w3.org" <xmlschema-dev@w3.org>
At 2009-04-30 22:06 +1000, Paul Steckler wrote:
>   I want to create an element, say "Foo" that contains a sequence 
> of elements which
>have different tags, say "Bar" and "Glob".  So these would be legal:
>    <Foo><Glob/><Bar/></Foo>
>   <Foo><Bar/><Glob/></Foo>
>   <Foo><Bar/><Glob/><Bar/></Foo>
>In the complexType for Foo elements, can you specify that it 
>contains a sequence
>of alternative elements, in arbitrary order?

Yes, it could be called an "unbounded choice".

Unless, perhaps, by "alternative" you mean that they alternate from 
one to the other?  I'm guessing not.

>Or do I have to create a wrapper element
>for the alternatives and place them in a union?


I hope the example below helps.

. . . . . . . Ken

t:\ftemp>type steckler1.xml

t:\ftemp>type steckler2.xml

t:\ftemp>type steckler3.xml

t:\ftemp>type steckler4-bad.xml

t:\ftemp>type steckler.xsd
<?xml version="1.0" encoding="US-ASCII"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">

  <xsd:documentation xml:lang="en">
    Paul's example

<xsd:element name="Foo">
     <xsd:choice maxOccurs="unbounded">
       <xsd:element name="Bar"/>
       <xsd:element name="Glob"/>


t:\ftemp>w3cschema-saxon steckler.xsd steckler1.xml
No validation errors.

t:\ftemp>w3cschema-saxon steckler.xsd steckler2.xml
No validation errors.

t:\ftemp>w3cschema-saxon steckler.xsd steckler3.xml
No validation errors.

t:\ftemp>w3cschema-saxon steckler.xsd steckler4-bad.xml
Validation error on line 1 column 18 of steckler4-bad.xml:
   In content of element <Foo>: The content model does not allow 
element <Baz> to appear
   here. Expected one of: Bar, Glob (See 
http://www.w3.org/TR/xmlschema-1/#cvc-complex-type clause 2.4)
No validation errors.


XQuery/XSLT/XSL-FO hands-on training - Los Angeles, USA 2009-06-08
Crane Softwrights Ltd.          http://www.CraneSoftwrights.com/x/
Training tools: Comprehensive interactive XSLT/XPath 1.0/2.0 video
Video lesson:    http://www.youtube.com/watch?v=PrNjJCh7Ppg&fmt=18
Video overview:  http://www.youtube.com/watch?v=VTiodiij6gE&fmt=18
G. Ken Holman                 mailto:gkholman@CraneSoftwrights.com
Male Cancer Awareness Nov'07  http://www.CraneSoftwrights.com/x/bc
Legal business disclaimers:  http://www.CraneSoftwrights.com/legal
Received on Sunday, 3 May 2009 02:22:37 UTC

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