是否可以在
XML模式中执行此类操作?
<xsd:complexType name="ItemsType">
<xsd:choice minOccurs="0" maxOccurs="unbounded">
<xsd:element ref="shirt"/>
<xsd:element ref="hat"/>
<xsd:element ref="umbrella"/>
</xsd:choice>
<xsd:choice minOccurs="1" maxOccurs="3">
<xsd:element ref="apple"/>
<xsd:element ref="banana"/>
<xsd:element ref="strawBerry"/>
</xsd:choice>
</xsd:complexType>
这显然是无效的.我想要的是可以有0或更多的第一选择.例如.可能有一个衬衫元素和一个帽子元素,或者根本没有衣服元素(因为minOccurs =“0”),然后是至少1个水果元素(我想要它,所以必须至少有一个,因为的minOccurs = “1”).
有办法吗?
谢谢你的帮助.
解决方法
< XSD:的complexType>期望只有一个子元素.将您的两个选项包含在单个< xsd:sequence>中.
例
<xsd:complexType name="ItemsType">
<xsd:sequence>
<xsd:choice minOccurs="0" maxOccurs="unbounded">
... clothes ...
</xsd:choice>
<xsd:choice minOccurs="1" maxOccurs="3">
... fruits ...
</xsd:choice>
</xsd:sequence>
</xsd:complexType>