开发者

why some schemas use <xsd:choice> instead of <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 na开发者_如何学Gome="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


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜