0
votes

I trying to create/correct the following XSD to match program logic. Current non-XSD logic allows the following attributes (XML representation below) to be parsed in any ordered. I am very green with XSD. This would be a valuable tool for parsing validation. Can XSD be created to allow processing of these attributes in any order to allow maxOccurs for Susp_O_CD? I know sequence will allow maxOccurs and all doesn't, but Susp_O_CD must be allowed to have up to five values, and any input order for StReas, StReas_N, ListSusp_T, and Susp_O_CD tags are required.

<PrimaryReason>
   <StReas>2</StReas>
   <StReas_N>Reason for stop test</StReas_N>
   <ListSusp_T>
       <Susp_T>8</Susp_T>
       <Susp_T>4</Susp_T>
   </ListSusp_T>
   <Susp_O_CD>00100</Susp_O_CD>
   <Susp_O_CD>00200</Susp_O_CD>
   <Susp_O_CD>00101</Susp_O_CD>
   <Susp_O_CD>00201</Susp_O_CD>
</PrimaryReason>

XSD:

<xs:element name="PrimaryReason" type="Reason_Set"/>

<xs:complexType name="Reason_Set">
    <xs:all>
        <xs:element name="StReas" type="StReas"/>
        <xs:element name="StReas_N" type="StReas_N"/>
        <xs:element name="Tr_ID" type="Tr_ID" minOccurs="0"/>
        <xs:element name="Tr_O_CD" type="Tr_O_CD" minOccurs="0"/>
        <xs:element name="EDU_sec_CD" type="EDU_sec_CD" minOccurs="0"/>
        <xs:element name="EDU_subDiv_CD" type="EDU_subDiv_CD" minOccurs="0"/>
        <xs:element name="ListSusp_T" minOccurs="0">
        <xs:complexType>
            <xs:sequence>
                <xs:element name="Susp_T" type="Susp_T" minOccurs="0" maxOccurs="9"/>
            </xs:sequence>
        </xs:complexType>
        </xs:element>
        <xs:element name="Susp_O_CD" type="Susp_O_CD"  minOccurs="0" maxOccurs="5"/>
    </xs:all>   
</xs:complexType>

Hopefully this can be done. I did try Group but it doesn't work with all tag. All suggests are welcome.

1

1 Answers

0
votes

In XSD 1.0, elements in an xs:all particle can only appear zero or one times.

This restriction is lifted in XSD 1.1 to allow any maxOccurs value.

So you need to decide whether you can move to XSD 1.1 (which is supported by relatively few schema processors: Xerces, Altova, and Saxon).

Incidentally, it's confusing to refer to your elements as attributes. "Attributes" is a technical term in XML. "name" and "maxOccurs" in your schema document are attributes; "Susp_O_CD" in your instance document is an element.

See also XSD - how to allow elements in any order any number of times?