序列内的 XSD 选择 [英] XSD choice inside sequence
问题描述
我理解并分别使用 xs:choice
和 xs:sequence
但我不明白 xs 里面的
是什么意思?xs:choice
:sequence
I understand and use xs:choice
and xs:sequence
separately but I do not understand what xs:choice
inside xs:sequence
mean?
<xs:element name="sports-content">
<xs:complexType>
<xs:sequence>
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element name="sports-metadata" />
<xs:element name="sports-event" />
<xs:element name="tournament" />
<xs:element name="schedule" />
</xs:choice>
</xs:sequence>
</xs:complexType>
</xs:element>
好的.此 XML 将有效.
Ok. This XML will be valid.
<sports-content>
<sports-metadata />
<tournament />
</sports-content>
这个 XML 是否有效?
Will this XML be valid or not?
<sports-content>
<sports-metadata />
<tournament />
<sports-metadata />
</sports-content>
推荐答案
XSD 中的 xs:sequence
元素是多余的;它可以被删除而不影响任何 XML 文档的有效性.xs:choice
周围的 xs:sequence
会很有用,例如,如果您希望选择总是在一个或多个元素之前或之后按顺序进行.
The xs:sequence
element in your XSD is superfluous; it can be removed without affecting validity of any XML document. An xs:sequence
around an xs:choice
would be useful, for example, if you wanted the choice to always be preceded or followed by one or more elements in sequence.
是的,您问题中的两个 XML 文档都对您的 XSD 有效(并且如果您删除 xs:choice
周围的 xs:sequence
包装器,它将继续有效.
Yes, both of the XML documents in your question are valid against your XSD (and will continue to be if you remove the xs:sequence
wrapper around xs:choice
.
这篇关于序列内的 XSD 选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!