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

Re: XSD for 'at least one of'

From: G. Ken Holman <gkholman@CraneSoftwrights.com>
Date: Thu, 06 Jan 2011 13:06:49 -0500
Message-Id: <>
To: xmlschema-dev@w3.org
At 2011-01-06 11:24 -0500, George Francis wrote:
>Apologies if this is a PAQ, I can't find the answer.
>How do I specify in my XSD that an element must contain at least one 
>of it's child elements?

By mandating a choice of mandatory children, not optional children.

>  I've tried the following:
><xs:complexType name="options">
><xs:choice minOccurs="1" maxOccurs="unbounded">
><xs:element name='month' type="month" minOccurs="0" />
><xs:element name='year' type="year" minOccurs="0" />
><xs:element name='day' type="day" minOccurs="0" />
>but it still doesn't seem to care if 'options' is empty.

Right, because you've allowed any of the choices to be empty.  If you 
make all of the choices mandatory, then the choice cannot be an empty 
choice and the element will not be empty of children.

<xs:complexType name="options">
  <xs:choice minOccurs="1" maxOccurs="unbounded">
   <xs:element name='month' type="month" />
   <xs:element name='year' type="year" />
   <xs:element name='day' type="day" />

I hope this helps.

. . . . . . . . . Ken

Contact us for world-wide XML consulting & instructor-led training
Crane Softwrights Ltd.          http://www.CraneSoftwrights.com/x/
G. Ken Holman                 mailto:gkholman@CraneSoftwrights.com
Legal business disclaimers:  http://www.CraneSoftwrights.com/legal
Received on Thursday, 6 January 2011 18:13:48 UTC

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