微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

为什么某些模式使用<xsd:choice>而不是<xsd:enumeration>?

如何解决为什么某些模式使用<xsd:choice>而不是<xsd:enumeration>?

| 我看到一个xml模式(EPP)鞭子在元素上使用了
xsd:choice
,即使我们可以改用
xsd:enumeration
 <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>
为什么在这种情况下他们更喜欢“ 0”而不是“ 1”? 谢谢     

解决方法

           为什么在这种情况下他们更喜欢xsd:choice而不是xsd:enumeration? 大概他们想要标签而不是支持的xml中的文本内容。 使用一个或另一个的决定几乎与您要支持的xml有关,因为它们做的事情完全不同。首选哪种xml格式是相当主观的。 另请参阅此相关问题。     ,        选择是在元素之间进行选择,而枚举则允许在一组值之间进行选择。值可以像示例中一样是字符串,但是如果要枚举多个元素对象,则必须使用choice。     

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。