我有以下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