2011-06-18 36 views
3

我看到了一个XML模式(EPP)whitch使用xsd:choice与元素,即使我们可以用xsd:enumeration代替:为什么有些模式使用<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> 

他们为什么喜欢xsd:choice而不是xsd:enumeration在这种情况下

由于

回答

2

为什么他们更喜欢在这种情况下使用xsd:choice而不是xsd:enumeration?

想必他们想在支持的XML中使用标签而不是文本内容。

决定使用一个或另一个几乎是你想支持的XML的问题,因为它们做的事情完全不同。哪个xml表单更好,这是非常主观的。

另请参阅此related question

3

选择为元件之间的选择,而枚举允许的一组值之间选择。值可以像你的例子中的字符串,但如果你想枚举几个元素对象,那么你将不得不使用选择。

相关问题