tags:

views:

192

answers:

1

I have an XSD file with an enumerated type. I'd like to create an "extended" XSD file, which adds some additional enumerations, but otherwise behaves just like the main XSD.

For example, the main XSD file contains this:

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

My imaginary extended XSD file would simply add "gold" to the "color" type. The existing "myColor" element would now be able to contain "gold", if it used this XSD instead of the main one.

Is this possible?

+2  A: 

How about something like this?

<!-- 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"/>
NJChim
How would I put these in separate files? If I use xsd:redefine in the extended XSD, and redefine colorEx, I'm limited to values that are already allowed in colorEx. So I can't add new values.
JW
I suppose I can make colorEx default to just a string type. This means that if I use the base XSD directly, there will be no restrictions on the type; any string will be allowed. But if I use the extended XSD, it will be restricted.
JW