Klaus Malorny wrote: > it is not a bug, it is correct that the schema you've created > accepts the <element> element that contains only the <element1>. > As both elements in the "element_group" group are optional, it > matches the non-existing elements after <element1>.
Thanks for confirming that it is not a bug. However, this seems inconsistent
to me. If I use:
<element name="test">
...
<group ref="test_group" minOccurs="0"/>
...
</element>
<group name="test_group">
<sequence>
<element name="field1" type="string" minOccurs="1"/>
<element name="field2" type="string" minOccurs="1"/>
</sequence>
</group>
The schema allows me to leave out <field1> and <field2> elements from the
<test> element even though they are mandatory in the group - i.e. it takes
notice of the minOccurs="0" attribute on the group reference. However, if the
situation is reversed (as in my original e-mail):
<element name="test">
...
<group ref="test_group" minOccurs="1"/>
...
</element>
<group name="test_group">
<sequence>
<element name="field1" type="string" minOccurs="0"/>
<element name="field2" type="string" minOccurs="0"/>
</sequence>
</group>
it ignores the minOccurs="1" attribute on the group reference and allows the
elements to be omitted.
> I'm not a schema expert, but I would create a choice of two,
> one requiring element2 and optionally accepting element3, the
> other requiring element3 (solely).
> ...
> <choice>
> <sequence>
> <element minOccurs="1" name="element2"/>
> <element minOccurs="0" name="element3"/>
> </sequence>
> <sequence>
> <element minOccurs="1" name="element3"/>
> </sequence>
> </choice>
> ...
Very many thanks, Klaus, that worked perfectly!
Regards,
Andrew
All opinions are completely my own - after all, who else would want to take
credit for them?
smime.p7s
Description: S/MIME cryptographic signature
