XML 任何已定义类型的组件集合的架构

XML Schema for collection of components of any of defined type

我已经定义了 inputTextTypeinputEmailType 类型的组件(它们的定义在这里并不重要)。我需要 components 任何数量的 inputText and/or inputEmail 的集合,以任何顺序(例如:文本、电子邮件、文本、文本)。我试过:

<xs:complexType name="componentsType">
    <xs:choice>
        <xs:element name="inputText" type="inputTextType" maxOccurs="unbounded" minOccurs="0"/>
        <xs:element name="inputEmail" type="inputEmailType" maxOccurs="unbounded" minOccurs="0"/>
    </xs:choice>
</xs:complexType>

然后在验证时 XML

<components>
    <inputText>
        <label>label 1</label>
        <name>as</name>
    </inputText>
    <inputText>
        <label>label 2</label>
        <name>ghyyy6</name>
    </inputText>
    <inputEmail>
        <label>drg</label>
        <name>rgtght</name>
    </inputEmail>
</components>

我有一个错误 cvc-complex-type.2.4.a: Invalid content was found starting with element 'inputEmail'. One of '{inputText}' is expected.。 XML 是正确的(我需要它)。我应该如何修复 XSD?

上面的XML我把XSD改成了

<xs:complexType name="componentsType">
    <xs:choice>
        <xs:element name="inputText" type="inputTextType" maxOccurs="unbounded" minOccurs="0"/>
        <xs:element name="inputEmail" type="inputEmailType" maxOccurs="unbounded" minOccurs="0"/>
    </xs:choice>
</xs:complexType>

它起作用了,但我无法定义文本、电子邮件、文本、文本,只能先定义所有文本,然后再定义所有电子邮件。

将出现限制向上移动 xs:choice:

<xs:choice minOccurs="0" maxOccurs="unbounded">
    <xs:element name="inputText" type="inputTextType"/>
    <xs:element name="inputEmail" type="inputEmailType"/>
</xs:choice>