Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Restricted type "derivation" help - concrete example within

From: "David Aldridge" <daldridge@--------.--->
To: <xmlschema-dev@--.--->
Date: 6/23/2004 6:48:00 AM
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


transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent