问题
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>
to make the question clear , I will use this example instead :
<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>
an xml example using that schema :
<!--using choice-->
<sport>
<football/>
</sport>
<!--using enumeration-->
<sport>football</sport>
why they prefer xsd:choice
instead of xsd:enumeration
in this situation ?
Thanks
回答1:
why they prefer xsd:choice instead of xsd:enumeration in this situation ?
Presumably they want a tag instead of text content in the supported 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.
See also this related question.
回答2:
Choice is for choice between elements, while enumeration allow choice between a set of values. The values can be string like in your example, but if you wanted to enumerate several element objects, then you would have to use choice.
来源:https://stackoverflow.com/questions/6395617/why-some-schemas-use-xsdchoice-instead-of-xsdenumeration