为什么有些模式使用 <xsd:choice>而不是<xsd:enumeration>? [英] why some schemas use <xsd:choice> instead of <xsd:enumeration>?
问题描述
我看到了一个使用 xsd:choice
即使我们可以使用 xsd:enumeration
代替:
I saw an xml schema ( EPP ) whitch used xsd:choice
with an element even if we can use xsd:enumeration
instead :
<element name="access" type="epp:dcpAccessType"/>
<complexType name="dcpAccessType">
<choice>
<element name="all"/>
<element name="none"/>
<element name="null"/>
<element name="other"/>
<element name="personal"/>
<element name="personalAndOther"/>
</choice>
</complexType>
为了让问题更清楚,我将使用这个例子:
<element name="sport" type="sportType"/>
<!-- using choice-->
<complexType name="sportType">
<choice>
<element name="football"/>
<element name="tennis"/>
</choice>
</complexType>
<!-- Or using enumeration-->
<simpleType name="sportType">
<restriction base="string">
<enumeration value="football"/>
<enumeration value="tennis"/>
</restriction>
</simpleType>
使用该架构的 xml 示例:
<!--using choice-->
<sport>
<football/>
</sport>
<!--using enumeration-->
<sport>football</sport>
为什么他们更喜欢 xsd:choice
而不是 xsd:enumeration
在这种情况下?
why they prefer xsd:choice
instead of xsd:enumeration
in this situation ?
谢谢
推荐答案
为什么在这种情况下他们更喜欢 xsd:choice 而不是 xsd:enumeration?
why they prefer xsd:choice instead of xsd:enumeration in this situation ?
大概他们想要一个标签而不是支持的 xml 中的文本内容.
Presumably they want a tag instead of text content in the supported xml.
决定使用其中一个几乎是您想要支持的 xml 的问题,因为它们做完全不同的事情.哪种 xml 形式更可取是很主观的.
The decision to use one or the other is pretty much a matter of xml you want to support, as they do quite different things. Which xml form is preferable is quite subjective.
另请参阅此相关问题.
这篇关于为什么有些模式使用 <xsd:choice>而不是<xsd:enumeration>?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!