[英]XSD with elements in any order and unbounded multiplicity
我需要产生一个XSD。 在根元素下,7个不同元素中的任何一个可以出现0、1或多次出现,并且这些元素可以以任何顺序出现。
我不能使用序列,因为元素不一定按预定义的顺序排列。 这将是一个有效的架构,但是它施加了过于严格的限制:
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="data">
<xs:complexType>
<xs:sequence>
我不能全部使用,因为它不允许maxOccurs不受限制,所以这是一个无效的架构:
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="data">
<xs:complexType>
<xs:all>
<xs:element name="address" minOccurs="0" maxOccurs="unbounded">
我觉得我已经遇到了XSD的另一个限制,但是我只是想问一下,因为我是XML Schema的新手。
在每个元素上使用带有maxOccurs="1"
的choice
块。 这样可以确保a,b或c中至少有一个,但每个不超过一个。
<xs:choice minOccurs="1" maxOccurs="unbounded">
<xs:element name="a" maxOccurs="1"/>
<xs:element name="b" maxOccurs="1"/>
<xs:element name="c" maxOccurs="1"/>
</xs:choice>
在此架构下,以下所有内容均有效:
<root>
<a/>
</root>
<root>
<a/>
<b/>
</root>
<root>
<b/>
<a/>
</root>
<root>
<c/>
<a/>
</root>
<root>
<a/>
<c/>
<b/>
</root>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.