Occurence constraints in XSD

R

Roland

hi all

having designed my schema to use repeating groups of elements, I found
that some applications (eg. Microsoft InfoPath) refused to recognised
that element as a repeating element.

I subsequently found that out of the three possible ways (that I know
of) of declaring repeating elements in xsd, only one of these was
understood:

a) occurence constraint on the child element contained in a sequence
compositor IS recognised as a repeating element.
b) occurence constraint on sequence compositor containing the child
element IS NOT recognised as a repeating element.
c) occurence constraint on group reference where the goup is a
sequence compositor containing the child element IS NOT recognised as
a repeating element.

as can be seen from the following xsd schema:

<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:element name="testRepeating">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="RepeatingChildren">
<xsd:complexType>
<xsd:sequence>
<xsd:element ref="repeatingChild" minOccurs="0"
maxOccurs="10"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="RepeatingSequence">
<xsd:complexType>
<xsd:sequence minOccurs="0" maxOccurs="10">
<xsd:element ref="repeatingChild"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="RepeatingGroup" type="repeatingGroupType">
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="repeatingChild" type="xsd:string"/>
<xsd:group name="repeatingGroup">
<xsd:sequence>
<xsd:element ref="repeatingChild"/>
</xsd:sequence>
</xsd:group>
<xsd:complexType name="repeatingGroupType">
<xsd:group ref="repeatingGroup" minOccurs="0" maxOccurs="10"/>
</xsd:complexType>
</xsd:schema>


only the "//testRepeating/RepeatingChildren/repeatingChild" XPath in
a document instance based on the above schema was treated by the
application as a repeating element.


ignoring that particular limitation, I would like to know which of the
three models above that allow repeating elements is the most
recommended approach, and why ?


thanks
roland
 
O

Oleg Tkachenko

Roland said:
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:element name="testRepeating">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="RepeatingChildren">
<xsd:complexType>
<xsd:sequence>
<xsd:element ref="repeatingChild" minOccurs="0"
maxOccurs="10"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="RepeatingSequence">
<xsd:complexType>
<xsd:sequence minOccurs="0" maxOccurs="10">
<xsd:element ref="repeatingChild"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="RepeatingGroup" type="repeatingGroupType">
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="repeatingChild" type="xsd:string"/>
<xsd:group name="repeatingGroup">
<xsd:sequence>
<xsd:element ref="repeatingChild"/>
</xsd:sequence>
</xsd:group>
<xsd:complexType name="repeatingGroupType">
<xsd:group ref="repeatingGroup" minOccurs="0" maxOccurs="10"/>
</xsd:complexType>
</xsd:schema>
....
ignoring that particular limitation, I would like to know which of the
three models above that allow repeating elements is the most
recommended approach, and why ?

I'd say all three are just different ways to express the same constraint.
Second and third are a bit redundant ones for only defining maxOccurence of a
single element, but I believe all of them are valid though.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top