maxOccurs 为无界,但不要考虑元素的顺序 (xs:all) [英] maxOccurs as unbounded, but don't think of order of elements (xs:all)
问题描述
我有一个 XSD 文件,其中有以下情况:
I have a XSD file in which I have the following situation:
<xs:element name='test'>
<xs:complexType>
<xs:all>
<xs:element ref='el1' minOccurs='0' maxOccurs='1'/>
<xs:element ref='el2' minOccurs='0' maxOccurs='1'/>
<xs:element ref='el3' minOccurs='0' maxOccurs='1'/>
<xs:element ref='el4' minOccurs='0' maxOccurs='1'/>
<xs:element ref='el5' minOccurs='0' maxOccurs='1'/>
<xs:element ref='el6' minOccurs='0' maxOccurs='1'/>
<xs:element ref='el7' minOccurs='0' maxOccurs='1'/>
<xs:element ref='el8' minOccurs='0' maxOccurs='unbounded'/>
</xs:all>
<xs:attribute name='attr1' use='optional' type='yesno'/>
</xs:complexType>
</xs:element>
现在的问题是,到目前为止这还行不通,因为我不能在 all
元素中包含 maxOccurs='unbounded'
.有什么办法可以实现这一点,例如使用 xs:choice
?
And now the problem is, this isn't working so far, cause I can't have maxOccurs='unbounded'
within the all
element. Is there any way to achieve this, e.g. with using xs:choice
?
推荐答案
为了保留您想要的基数,XSD 1.0 中的唯一方法是用另一个重复元素包装您的重复元素,如下所示:
To preserve the cardinality you want, the only way in XSD 1.0 is to wrap your repeating element with another one, like so:
<xs:element name='test'>
<xs:complexType>
<xs:all>
<xs:element ref='el1' minOccurs='0'/>
<xs:element ref='el2' minOccurs='0'/>
<xs:element ref='el3' minOccurs='0'/>
<xs:element ref='el4' minOccurs='0'/>
<xs:element ref='el5' minOccurs='0'/>
<xs:element ref='el6' minOccurs='0'/>
<xs:element ref='el7' minOccurs='0'/>
<xs:element ref='el8w' minOccurs='0'/>
</xs:all>
<xs:attribute name='attr1' type='yesno'/>
</xs:complexType>
</xs:element>
<xs:element name="el8w">
<xs:complexType>
<xs:sequence>
<xs:element ref="el8" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>
模仿 xs:all
的(重复)选择(即允许散布具有指定基数的元素)不能强制出现单个粒子.
The (repeating) choice that would mimic the xs:all
(i.e. allow for interspersed elements with the indicated cardinality) can't enforce the occurrence of individual particles.
这篇关于maxOccurs 为无界,但不要考虑元素的顺序 (xs:all)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!