0

In this example (from Exchange Web Services XSD)

 <xs:complexType name="ArrayOfAttendeeConflictData">
     <xs:choice minOccurs="0" maxOccurs="unbounded">
         <xs:element minOccurs="1" maxOccurs="1" name="UnknownAttendeeConflictData" nillable="true" type="t:UnknownAttendeeConflictData" />
         <xs:element minOccurs="1" maxOccurs="1" name="IndividualAttendeeConflictData" nillable="true" type="t:IndividualAttendeeConflictData" />
        <xs:element minOccurs="1" maxOccurs="1" name="TooBigGroupAttendeeConflictData" nillable="true" type="t:TooBigGroupAttendeeConflictData" />
        <xs:element minOccurs="1" maxOccurs="1" name="GroupAttendeeConflictData" nillable="true" type="t:GroupAttendeeConflictData" />
     </xs:choice>
 </xs:complexType>

Does it mean a valid XML can have UnknownAttendeeConflictData, IndividualAttendeeConflictData, TooBigGroupAttendeeConflictData and GroupAttendeeConflictData in any order but only one instance of each?

kjhughes
  • 106,133
  • 27
  • 181
  • 240
venkat
  • 11
  • 3

1 Answers1

0

No, alone maxOccurences="1" on the children of xs:choice will not prohibit the children of xsd:choice from appearing more than once.

maxOccurs="unbounded" on xsd:choice means that there can be an unbounded number of choices. For each such choice, the XML document will be able to have one occurrence due to the maxOccurences="1", but next time around this can repeat due to xsd:choice/@maxOccurences="unbounded". So those elements listed as children of an xsd:choice/@maxOccurences="unbounded" will be able to appear multiple times in any order.

If as an XSD author you want such elements to appear once in any order, consider using xsd:all. Also note that occurrence constraints minOccurs and maxOccurs default to 1 anyway, so listing them explicitly isn't really required.

Community
  • 1
  • 1
kjhughes
  • 106,133
  • 27
  • 181
  • 240