Re: XSD for 'at least one of'

Hi George,

On 1/6/2011 11:24 AM, 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?
>  I've tried the following:
>
> <xs:complexTypename="options">
>
> <xs:choiceminOccurs="1"maxOccurs="unbounded">
>
> <xs:elementname='month'type="month"minOccurs="0"/>
>
> <xs:elementname='year'type="year"minOccurs="0"/>
>
> <xs:elementname='day'type="day"minOccurs="0"/>
>
> </xs:choice>
>
> </xs:complexType>
>
>
> but it still doesn't seem to care if 'options' is empty.

You made it legal to choose any of the choices zero times.  So, at least 
one time, you have to choose one of the elements and have it be there at 
least zero times.  You need to adjust the minOccurs on the elements 
inside the choice.  The minOccurs on the choice controls how many times 
you must make a choice.  The minOccurs on the things inside the choice 
controls how many times you must have that thing when you choose it.

Kevin

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

Received on Thursday, 6 January 2011 18:35:08 UTC