我有以下的XSD代码:
<xsd:complexType name="questions">
<xsd:sequence>
<xsd:element name="location" type="location"/>
<xsd:element name="multipleChoiceInput" type="multipleChoiceInput" minOccurs="0" maxOccurs="unbounded"/>
<xsd:element name="textInput" type="textInput" minOccurs="0" maxOccurs="unbounded"/>
<xsd:element name="pictureInput" type="pictureInput" minOccurs="0"/>
</xsd:sequence>
</xsd:complexType>
这里的问题是:元素位置、multipleChoiceInput等必须按照它们被声明的顺序出现。我不想让这种情况发生,在验证过程中,序列应该不相关。我该如何实现这一点?
我尝试过的另一个可能性是:
<xsd:complexType name="questions">
<xsd:choice maxOccurs="unbounded">
<xsd:element name="location" type="location"/>
<xsd:element name="multipleChoiceInput" type="multipleChoiceInput" minOccurs="0" maxOccurs="unbounded"/>
<xsd:element name="textInput" type="textInput" minOccurs="0" maxOccurs="unbounded"/>
<xsd:element name="pictureInput" type="pictureInput" minOccurs="0" maxOccurs="1"/>
</xsd:choice>
</xsd:complexType>
在这个例子中,序列的顺序不再重要,我可以拥有任意数量的元素("all"不能让我这样做)。但是,我仍然面临min-和maxOccurs的问题。在此示例中,我可以拥有尽可能多的"pictureInput",这违反了我想要只有0个或1个的约束条件。非常感谢你的帮助!
<xs:any>
就是你的好朋友。 - Tomalak