XSD XML 所有序列 maxOccurs

XSD XML all sequence maxOccurs

我试图create/correct以下XSD来匹配程序逻辑。当前的非 XSD 逻辑允许以任何顺序解析以下属性(下面的 XML 表示)。 XSD 我很绿。这将是一个有价值的解析验证工具。是否可以创建 XSD 以允许以任何顺序处理这些属性以允许 Susp_O_CD 的 maxOccurs?我知道序列将允许 maxOccurs 而所有不允许,但必须允许 Susp_O_CD 最多有五个值,以及 StReas、StReas_N、ListSusp_T 和 [= 的任何输入顺序21=] 标签是必需的。

<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>

希望可以做到。我确实尝试过 Group 但它不适用于所有标签。欢迎所有建议。

在XSD 1.0中,xs:all粒子中的元素只能出现0次或一次。

此限制在 XSD 1.1 中取消,允许任何 maxOccurs 值。

因此您需要决定是否可以迁移到 XSD 1.1(相对较少的模式处理器支持它:Xerces、Altova 和 Saxon)。

顺便说一下,将您的元素称为属性会造成混淆。 "Attributes" 是 XML 中的一个技术术语。架构文档中的 "name" 和 "maxOccurs" 是属性; "Susp_O_CD" 在您的实例文档中是一个元素。

另见 XSD - how to allow elements in any order any number of times?