2009-06-10 82 views
3

我有一個枚舉類型的XSD文件。我想創建一個「擴展」的XSD文件,它增加了一些額外的枚舉,但其他行爲就像主要的XSD一樣。擴展XSD文件

例如,主XSD文件包含此:

<xsd:simpleType name="color"> 
    <xsd:restriction base="xsd:string"> 
     <xsd:enumeration value="red"></xsd:enumeration> 
     <xsd:enumeration value="orange"></xsd:enumeration> 
     <xsd:enumeration value="yellow"></xsd:enumeration> 
    </xsd:restriction> 
</xsd:simpleType> 
... 
<xsd:element name="myColor" type="color" /> 

我的假想延長XSD文件將簡單地添加「黃金」到「色」的類型。現在的「myColor」元素現在可以包含「黃金」,如果它使用這個XSD而不是主要的。

這可能嗎?

回答

4

這樣的事情呢?

<!-- Your base enumeration --> 
<xsd:simpleType name="color"> 
    <xsd:restriction base="xsd:string"> 
     <xsd:enumeration value="red"/> 
     <xsd:enumeration value="orange"/> 
     <xsd:enumeration value="yellow"/> 
    </xsd:restriction> 
</xsd:simpleType> 

<!-- You extended enumeration --> 
<xsd:simpleType name="colorEx"> 
    <xsd:restriction base="xsd:string"> 
     <xsd:enumeration value="gold"/> 
    </xsd:restriction> 
</xsd:simpleType> 


<xsd:simpleType name="color_union"> 
    <xsd:union memberTypes="colorEx color"/> 
</xsd:simpleType> 

<xsd:element name="myColor" type="color_union"/> 
+2

我會如何把它們放在單獨的文件中?如果我在擴展XSD中使用xsd:redefine並重新定義了colorEx,那麼我僅限於colorEx中已經允許的值。所以我不能添加新的值。 – 2009-06-10 19:21:32