overriding sub-elements with XSD

Hello.  I have two complexTypes, one of which extends the other, and both
which have a sub-element with the same name.  However, the details of that
element (type, min/maxOccurs,, etc.) can vary.  In this example below,
"parent" must have one "subElement" and "child" must have two:

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">

    <xs:complexType name="ParentClass">
        <xs:sequence>
            <xs:element name="subElement" minOccurs="1" maxOccurs="1"/>
        </xs:sequence>
    </xs:complexType>

    <xs:complexType name="ChildClass">
        <xs:complexContent>
            <xs:extension base="ParentClass">
                <xs:sequence>
                    <xs:element name="subElement" minOccurs="2"
maxOccurs="2"/>
                </xs:sequence>
            </xs:extension>
        </xs:complexContent>
    </xs:complexType>

    <xs:element name="root">
        <xs:complexType>
            <xs:sequence>
                <xs:element name="parent" type="ParentClass"/>
                <xs:element name="child" type="ChildClass"/>
            </xs:sequence>
        </xs:complexType>
    </xs:element>

</xs:schema>

However, when I create an XML file, "child" actually has three
"subElements:" one from the "ParentClass" it extends and the two it defines
itself.  Does anybody know a way around this?  I am basically hoping for an
"oo-style" solution, where the child's sub-element _overrides_ the parent's
sub-element of the same name.  Is that possible in XSD?

Thanks.

Received on Wednesday, 29 September 2010 17:12:55 UTC