如何限制复杂类型在xsd中按顺序出现?

如何限制复杂类型在xsd中按顺序出现?,xsd,Xsd,我希望为以下示例性xml使用xsd: <Action name="noname"> <choices> <choice attrib1="hi" attrib2="hello" attrib3="test" /> <choice attrib1="hi1" attrib2="hello1" attrib3="test1" /> <choice attrib1="hi2" attrib2="hello2" attrib3="test3" /&g

我希望为以下示例性xml使用xsd:

<Action name="noname">
<choices>
<choice attrib1="hi" attrib2="hello" attrib3="test" />
<choice attrib1="hi1" attrib2="hello1" attrib3="test1" />
<choice attrib1="hi2" attrib2="hello2" attrib3="test3" />
<choice attrib1="hi" />
</choices>
</Action>


正如你在上面看到的。我希望至少有一个没有“attrib2”和“attrib3”的“choice”。如何实现这一点?

我不确定是否完全理解,但您可以根据需要声明属性attrib1,并使用minOccurs=“1”声明choice元素。像这样:

<xs:element name="choices">
    <xs:complexType>
        <xs:sequence>
            <xs:element name="choice" minOccurs="1" maxOccurs="unbounded">
                <xs:complexType>
                    <xs:simpleContent>
                        <xs:extension base="xs:string">
                            <xs:attribute name="attrib1" type="xs:string" use="required"/>
                            <xs:attribute name="attrib2" type="xs:string"/>
                            <xs:attribute name="attrib3" type="xs:string"/>
                        </xs:extension>
                    </xs:simpleContent>
                </xs:complexType>
            </xs:element>
        </xs:sequence>
    </xs:complexType>
</xs:element>

然而,这可能会对您造成超出您需要的限制。所有选项元素都需要attrib1吗