[xsd-users] Support for a sequence of choice elements of polymorphic type

Damon Southworth xsd at cloudydaze.co.uk
Thu Oct 10 12:29:59 EDT 2013


On 10/10/13 16:50, Boris Kolpackov wrote:
> Hi Damon,
>
> Damon Southworth <xsd at cloudydaze.co.uk> writes:
>
>> Can the xsd cxx XML compiler also produce a single list of objects
>> with a type of the common parent class for the polymorphic choices
>> with a common parent class rather than a sperate list of each
>> choice.?
> On 10/10/13 16:50, Boris Kolpackov wrote:
>
> Yes, but you will need to modify the schema a bit (you can do it
> only for the XSD-to-C++ compilation): you will need to create
> an abstract substitution group root element (of type Element_Type)
> and use it as the only element in MyListType. Then derive Element_A
> and Element_B from this root element (in the substitution groups
> sense). This way they can be substituted for the element in
> MyListType. Once this is done, compile your schema with the
> --generate-polymorphic --polymorphic-type Element_Type options,
> and you will get a sequence that will contain either Element_A
> or Element_B, polymorphically
Thanks. Yes, I already tried this and it does works but does it not also 
means that the xml source needs to change too? Originally the xml source 
would look like this:

<MyListType>
     <Element_A name="Element_A"/>
     <Element_B name="Element_B"/>
     ...
</MyListType>

whereas now it would look like this

<MyListType>
     <Element_Type name="Element_A"/ xsi:type="Element_A">
     <Element_Type name="Element_B"/ xsi:type="Element_B">
     ...
</MyListType>

thus moving the list element type mapping from the schema into the xml 
source?

Damon.





-- 
Damon Southworth



More information about the xsd-users mailing list