Re: xsd:group and minOccurs

Hi Eddie,

>>Since the "agroup" reference in the "test" element has an implied
>>minOccurs="1" would a document with an empty "test" element be valid against
>>the schema?
>
> Yes, I believe this would be valid. I think the place for this in
> the spec is "3.8.4 Model Group Validation Rule" [1] which has the
> following paragraph:
>
> "Nothing in the above should be understood as ruling out groups whose 
> {particles} is empty: although no sequence can be ·valid· with respect 
> to such a group whose {compositor} is choice, the empty sequence is 
> ·valid· with respect to empty groups whose {compositor} is sequence or 
> all. "
>
> So, this means that for <all> and <sequence> you are allowed to have 
> empty particles but for <choice> this would not be valid.

I agree with your conclusion, but now with how you got to it. A group
whose {particles} is empty is a group that doesn't specify any
particles, for example:

  <xs:sequence />

or:

  <xs:choice />

or:

  <xs:all />

A sequence or an all group with no particles, as above, is fine -- it
just means that it matches an empty sequence of elements in the
instance. Having a choice between an empty set of particles is
invalid, on the other hand, because each time you have a choice you
must choose something, and if you have nothing to choose from then you
cannot choose anything :)

A model group like:

  <xsd:choice>
    <xsd:element name="A" minOccurs="0" type="xsd:string" />
    <xsd:element name="B" minOccurs="0" type="xsd:string" />
    <xsd:element name="C" minOccurs="0" type="xsd:string" />
  </xsd:choice>

is a choice model group that has three element particles. All those
particles are *optional* (have a minimum occurrence of 0) but the
model group still has particles. So this is perfectly valid
(thankfully!).

Cheers,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/

Received on Thursday, 29 August 2002 04:14:22 UTC