Restricted type "derivation" help - concrete example within

I have an old C++ class heirarchy that I'm trying to migrate to being
mostly defined via XML rather than C++ code, and have run into a snag
with specifying the appropriate type in my schema.  Rather than
explaining it in prose, below are example .XSD and .XML implementations
that illustrate the issue.  My comments and question follow the source.
 
test.xsd
======================
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema'>
 
<xs:complexType name="ColorType">
    <xs:sequence>
        <xs:element name="red" type="xs:unsignedByte"/>
        <xs:element name="green" type="xs:unsignedByte"/>
        <xs:element name="blue" type="xs:unsignedByte"/>
        <xs:element name="alpha" type="xs:unsignedByte"/>
    </xs:sequence>
</xs:complexType>
 
<xs:complexType name="ShapeType" abstract="true">
    <xs:sequence>
        <xs:element name="color" type="ColorType"/>
    </xs:sequence>
    <xs:attribute name="name" type="xs:string" use="required"/>
</xs:complexType>
<xs:element name="Shape" type="ShapeType" abstract="true"/>
 
<xs:complexType name="CircleType">
    <xs:complexContent>
        <xs:extension base="ShapeType">
            <xs:sequence>
                <xs:element name="radius" type="xs:unsignedByte"/>
            </xs:sequence>
        </xs:extension>
    </xs:complexContent>
</xs:complexType>
<xs:element name="Circle" type="CircleType" substitutionGroup="Shape"/>
 
<xs:complexType name="SquareType">
    <xs:complexContent>
        <xs:extension base="ShapeType">
            <xs:sequence>
                <xs:element name="length" type="xs:unsignedByte"/>
            </xs:sequence>
        </xs:extension>
    </xs:complexContent>
</xs:complexType>
<xs:element name="Square" type="SquareType" substitutionGroup="Shape"/>
 
<xs:complexType name="MickeyMouseHeadType1">
    <xs:complexContent>
        <xs:extension base="ShapeType">
            <xs:sequence>
                <xs:element name="LeftEar" type="CircleType"/>
                <xs:element name="RightEar" type="CircleType"/>
                <xs:element name="Head" type="CircleType"/>
            </xs:sequence>
        </xs:extension>
    </xs:complexContent>
</xs:complexType>
<xs:element name="MickeyMouseHead1" type="MickeyMouseHeadType1"
substitutionGroup="Shape"/>
 
<!--xs:complexType name="MickeyMouseHeadType2">
    <xs:complexContent>
        <xs:extension base="ShapeType">
            <xs:sequence>
                <xs:element ref="Circle">
                    <xs:complexType>
                        <xs:complexContent>
                            <xs:restriction base="CircleType">
                                <xs:attribute name="name"
type="xs:string" use="required" fixed="LeftEar"/>
                            </xs:restriction>
                        </xs:complexContent>
                    </xs:complexType>
                </xs:element>
                <xs:element ref="Circle">
                    <xs:complexType>
                        <xs:complexContent>
                            <xs:restriction base="CircleType">
                                <xs:attribute name="name"
type="xs:string" use="required" fixed="RightEar"/>
                            </xs:restriction>
                        </xs:complexContent>
                    </xs:complexType>
                </xs:element>
                <xs:element ref="Circle">
                    <xs:complexType>
                        <xs:complexContent>
                            <xs:restriction base="CircleType">
                                <xs:attribute name="name"
type="xs:string" use="required" fixed="Head"/>
                            </xs:restriction>
                        </xs:complexContent>
                    </xs:complexType>
                </xs:element>
            </xs:sequence>
        </xs:extension>
    </xs:complexContent>
</xs:complexType>
<xs:element name="MickeyMouseHead2" type="MickeyMouseHeadType2"
substitutionGroup="Shape"/-->
 
<xs:element name="Canvas">
    <xs:complexType>
        <xs:sequence>
            <xs:element ref="Shape" minOccurs="0"
maxOccurs="unbounded"/>
        </xs:sequence>
    </xs:complexType>
</xs:element>
 
</xs:schema>
=================
 
test.xml
=================
<?xml version="1.0" encoding="UTF-8"?>
<Canvas xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="test.xsd">
    <Circle name="Circle1">
        <color>
            <red>1</red>
            <green>2</green>
            <blue>3</blue>
            <alpha>4</alpha>
        </color>
        <radius>5</radius>
    </Circle>
     <MickeyMouseHead1 name="MMHead1">
         <color>
             <red>11</red>
             <green>22</green>
             <blue>33</blue>
             <alpha>44</alpha>
         </color>
         <LeftEar name="LeftEar">
             <color>
                 <red>1</red>
                 <green>2</green>
                 <blue>3</blue>
                 <alpha>4</alpha>
             </color>
             <radius>5</radius>
         </LeftEar>
         <RightEar name="RightEar">
             <color>
                 <red>1</red>
                 <green>2</green>
                 <blue>3</blue>
                 <alpha>4</alpha>
             </color>
             <radius>5</radius>
         </RightEar>
         <Head name="Head">
             <color>
                 <red>1</red>
                 <green>2</green>
                 <blue>3</blue>
                 <alpha>4</alpha>
             </color>
             <radius>5</radius>
         </Head>
     </MickeyMouseHead1>
</Canvas>
=================
 
 
COMMENTS / QUESTIONS:
 
The schema and xml content are valid (note that 'MickeyMouseHeadType2'
is commented out, as it in invalid content), but not sufficient for my
C++ loading code, as it knows how to create/instantiate <Circle> and
<Square>s, not <LeftEar>, <RightEar>, and <Head>s.  I would *prefer* to
come up with a workable solution for 'MickeyMouseHeadType2', as that
would allow .XML thusly:
 
...
     <MickeyMouseHead2 name="MMHead2">
         <color ... />
         <Circle name="LeftEar"> ...(contents)... </Circle>
         <Circle name="RightEar"> ...(contents)... </Circle>
         <Circle name="Head"> ...(contents)... </Circle>
     </MickeyMouseHead2>
...
 
Any ideas?
 
Thanks!
David

Received on Wednesday, 23 June 2004 12:56:02 UTC