[xsd-users] Hierarchies and code generation.

Klaim - Joël Lamotte mjklaim at gmail.com
Wed Mar 2 03:40:12 EST 2011


Hi,

I'm having troubles working on an xsd definition to generate an XML-format
language parser in C++.

Here is what I want to have in the end in C++ (in a specific namespace) :

 1. an abstract class Object. It's a common interface.
 2. child classes of Object : Object_Unknown, Object_Video, Object_Sprite,
Object_Audio, Object_Sprite
 3. an Object should have a "list" of children Object objects. As Element is
abstract, the children should be of Object child class types (2.).
 4. I still want to use the specific xml interface of the child types in the
"list" element :

<object id="my_object" >
    <children>
        <object ... />
        <sprite > <position x="1" y="2" /> </sprite> <--- specific interface
of a child type
    </children>
</object>



To achieve all this I tried several variant of the following :

<xs:complexType name="object" abstract="true" ... >

    ...blahblah
    <xs:sequence>
         <xs:element name="children" type="list_object" />
    </xs:sequence>


</xs:complexType>

child element types...
<xs:complexType name="object_unknown" ... />
<xs:complexType name="object_sprite" ... />
<xs:complexType name="object_audio" ... />

etc.

<xs:complexType name="list_object">

   <xs:sequence maxOccur="unbouded" minOccur="0" >
       <xs:element name="object" type="object_unknown" />
       <xs:element name="sprite" type="object_sprite" />
       <xs:element name="audio" type="object_audio" />
        etc.
   </xs:sequence>


But the generated C++ code of list_object will never expose a sequence of
"object" types, using
the common interface to list all the object instances without knowing the
child type.
It currently expose sequences of child object types, and that follows the
xsd correctly.


So, is there a way to make my list_object provide a sequence of "object"?

Thanks for your time.


Joël Lamotte


More information about the xsd-users mailing list