[英]XML schema for no sequence and multiple occurs
Mother
标签内的元素可以是Son
或Daughter
Son
元素或Daughter
元素没有任何顺序。 Son
不能兼任我(只有一个儿子)。 Daughter
可以是多个(多个女儿)。 所以我的问题是如何为此编写XML模式。 这就是我写的 我尝试使用<xsd:sequence>
和<xsd:choice>
代替<xsd:all>
。 但是我不知道该如何克服。
<xsd:complexType name="Mother">
<xsd:all>
<xsd:element name="Son" type="string" minOccurs="0" maxOccurs="1"/>
<xsd:element name="Daughter" type="string" minOccurs="0" maxOccurs="1"/>
</xsd:all>
</xsd:complexType>
-------------------------------这些是正确的XML文件----------------- -------------------
<Mother>
<Son>Jhon</Son>
<Daughter>Rose</Daughter>
<Daughter>Ann</Daughter>
</Mother>
<Mother>
<Daughter>Rose</Daughter>
<Son>Jhon</Son>
<Daughter>Ann</Daughter>
</Mother>
<Mother>
<Daughter>Rose</Daughter>
</Mother>
在这种特殊情况下,你可以做到这一点作为一个sequence
的零个或更多的Daughter
元素,其次是零或一个Son
,然后又零个或多个Daughter
小号
<xsd:complexType name="Mother">
<xsd:sequence>
<xsd:element name="Daughter" type="string" minOccurs="0" maxOccurs="unbounded"/>
<xsd:element name="Son" type="string" minOccurs="0" maxOccurs="1"/>
<xsd:element name="Daughter" type="string" minOccurs="0" maxOccurs="unbounded"/>
</xsd:sequence>
</xsd:complexType>
如果元素的内容不仅仅是一个字符串,那么我倾向于声明单独的顶级元素,并使用<xsd:element ref="Daughter" minOccurs=....
来引用它们。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.