Search code examples
xmlxsdxsd-1.0

Converting XSD 1.1 to 1.0 - Validation Error


When I try to validate this XSD:

<xs:group name="ValidityDateGroup">
    <xs:annotation>
        <xs:documentation>Reusable element group to be used where Valid From/Until needs to be captured in xs:date format</xs:documentation>
    </xs:annotation>
    <xs:all>
        <xs:element minOccurs="0" name="ValidFrom" type="xs:date"/>
        <xs:element minOccurs="0" name="ValidUntil" type="xs:date"/>
    </xs:all>
</xs:group>

<xs:complexType name="NameType">
    <xs:choice maxOccurs="unbounded" minOccurs="0">
        <!-- SNIP - many more choices here -->
        <xs:group ref="ValidityDateGroup"/>  <!-- THIS IS WHERE THE ERROR IS -->
     </xs:choice>
</xs:complexType>

I get the following error:

An 'all' model group must appear in a particle with '{'min occurs'}' = '{'max occurs'}' = 1, and that particle must be of a pair which constitutes the '{'content type'}' of a complex type definition.

The only way I have been able to get this to work as a 1.0 XSD is by changing the 'all' to a 'sequence':

<xs:group name="ValidityDateGroup">
    <xs:annotation>
        <xs:documentation>Reusable element group to be used where Valid From/Until needs to be captured in xs:date format</xs:documentation>
    </xs:annotation>
    <xs:sequence>
        <xs:element minOccurs="0" name="ValidFrom" type="xs:date"/>
        <xs:element minOccurs="0" name="ValidUntil" type="xs:date"/>
    </xs:sequence>
</xs:group>

but this forces a particular order.

Does anyone have any ideas how to get this XSD to work with XSD 1.0?


Solution

  • You can't get this to work with XSD 1.0. An "all" is not allowed as part of a choice. That's actually true in 1.1 as well.

    But what are you actually trying to achieve? You've got a choice with only one branch, which is obviously redundant, except that it specifies max=unbounded. Your "all" group says that From and Until are both optional and can appear in either order, and your max=unbounded says that the group can appear any number of times. To me, if that means anything, it means your content can contain any number of From elements and any number of Until elements, and they can occur in any order you like. That is, it means

    <choice maxOccurs="unbounded">
      <element name="From"/>
      <element name="Until"/>
    </choice>