why some schemas use <xsd:choice> instead of <xsd:enumeration>?

巧了我就是萌 提交于 2020-01-04 01:59:27

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!