我有以下XSD代码:使用XSD进行XML验证:如何避免关注元素的顺序?
<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>
在这个例子中,该序列真的没关系了,我能有这么多的元素,因为我想(什么是“所有”不会允许我去做)。但是我仍然遇到min-和maxOccurs的问题。在这个例子中,我可以有这么多的“pictureInput”,我想要的是0或1的限制是什么。
非常感谢您的帮助!
谢谢,但“所有”不能在我的情况,原因使用“全部”要求元素仅出现一次(min-和maxOccurs只能接受值0和1)。 – jcborges 2010-07-24 14:18:14
然后,也许''是你的朋友。 –
Tomalak
2010-07-24 14:19:39
雅在这种情况下任何需要使用。也会更新答案。 – YoK 2010-07-24 14:42:12