Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Any difference when you use min/maxOccurs at sequence rather than element level

Tags:

xsd

What I mean is are there any situations where this:

<xs:element name="MyType1">
    <xs:complexType>
        <xs:sequence>
            <xs:element maxOccurs="unbounded" name="MyType2">...</xs:element>
        </xs:sequence>
    </xs:complexType>
</xs:element>

has a different meaning to this:

<xs:element name="MyType1">
    <xs:complexType>
        <xs:sequence maxOccurs="unbounded">
            <xs:element name="MyType2">...</xs:element>
        </xs:sequence>
    </xs:complexType>
</xs:element>

Thanks in advance

like image 233
tom redfern Avatar asked Sep 19 '11 10:09

tom redfern


1 Answers

Generally speaking occurrence constraints (minOccurs or maxOccurs) on element groups (sequences or choices) mean that the whole group can be repeated whereas occurrence constraints on elements mean that the element can be repeated before the next element in the group appears.

If your sequence contains only one element, there is no difference.

<xs:sequence>
    <xs:element maxOccurs="unbounded" name="MyType2">...</xs:element>
</xs:sequence>

is equal to

<xs:sequence maxOccurs="unbounded">
    <xs:element name="MyType2">...</xs:element>
</xs:sequence>

and they both allow repeating the element <MyType2>. There will be a difference as soon as the sequence contains more than one element definition.

<xs:sequence>
    <xs:element maxOccurs="unbounded" name="MyType">...</xs:element>
    <xs:element maxOccurs="unbounded" name="foobar">...</xs:element>
</xs:sequence>

is not equal to

<xs:sequence maxOccurs="unbounded">
    <xs:element name="MyType">...</xs:element>
    <xs:element name="foobar">...</xs:element>
</xs:sequence>

The first one allows structures like

<MyType/>
<MyType/>
<foobar/>
<foobar/>

but the second one doesn't allow such a structure. Instead it allows structures like

<MyType/>
<foobar/>
<MyType/>
<foobar/>

which on the other hand are not allowed by the first definition.

like image 181
jasso Avatar answered Sep 25 '22 00:09

jasso