Re: xsd:group and minOccurs

Hi Gregory,

>The first submittal of this question had some errors in the sample schema
>(missing end tags),  thus this second submittal, sorry.
>
>I'm trying to get a definitive interpretation of the use of minOccurs
>attribute and an xsd:group reference.  The only thing I could find in the
>specification is at http://www.w3.org/TR/xmlschema-1/#element-group and it
>was a little unclear.
>
>I have an xsd:group defined with a sequence of optional elements as follows:
>
><xsd:group name="agroup">
>	<xsd:sequence>
>   		<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:sequence>
></xsd:group>
>
>And a reference to it as follows:
>
><xsd:element name="test">
>	<xsd:complexType>
>   		<xsd:sequence>
>			<xsd:element name="foo" minOccurs="0"
>type="xsd:string" />
>    			<xsd:group ref="agroup"/>
>    		</xsd:sequence>
>  	</xsd:complexType>
></xsd:element>
>
>
>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. In conclusion:
An empty "test" element would be valid against the above schema but if 
you change the group definition in the schema to:

<xsd:group name="agroup">
	<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>
</xsd:group>

then it would no longer be valid.

Cheers,
/Eddie

[1] http://www.w3.org/TR/xmlschema-1/#section-Model-Group-Validation-Rules

Received on Wednesday, 28 August 2002 19:59:01 UTC