代码之家  ›  专栏  ›  技术社区  ›  JW.

扩展XSD文件

  •  3
  • JW.  · 技术社区  · 16 年前

    我有一个具有枚举类型的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而不是主xsd。

    这有可能吗?

    1 回复  |  直到 16 年前
        1
  •  4
  •   NJChim    16 年前

    像这样的怎么样?

    <!-- 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"/>