扩展XSD文件

时间:2009-06-10 16:17:26

标签: xml 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文件只会将“gold”添加到“color”类型。现在的“myColor”元素现在可以包含“gold”,如果它使用的是XSD而不是主要的那个。

这可能吗?

1 个答案:

答案 0 :(得分: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"/>