[xsd-users] Trouble serializing subclasses.

Boris Kolpackov boris at codesynthesis.com
Sat May 17 01:13:09 EDT 2008


Hi Charles,

Charles Beyer <cjbeyer at gmail.com> writes:

> It only serializes the Values as type A, not the subclass B:
>
> <AList xmlns="stuff"
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xsi:schemaLocation="stuff Schema.xsd">
>   <Values>
>     <ID>99999999999</ID>
>   </Values>
>   <Values>
>     <ID>2</ID>
>   </Values>
> </AList>
>
> Using the exact same schema in .NET and C#, it properly serializes AList:
>
> <AList xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="stuff">
>   <Values xsi:type="B">
>     <ID>99999999999</ID>
>     <JD>5</JD>
>   </Values>
>   <Values xsi:type="B">
>     <ID>2</ID>
>     <JD>10</JD>
>   </Values>
> </AList>
>
>
> So, that's it.  I'm trying to get the xsd-tree serializer to work like
> my cs xsd serializer.  Any pointers?

You need to compile your schemas with the --generate-polymorphic
option. In XSD support for polymorphism (xsi:type and substitution
groups) is optional since the code that is not polymorphism-aware
is smaller and faster and the majority of schemas don't need it.

There are also an example in examples/cxx/tree/polymorphism/ that
shows how to parse/serialize polymorphic XML documents as well as
Section 2.11, "Mapping for xsi:type and Substitution Groups" in
the C++/Tree Mapping User Manual that gives some extra pointers
on working with polymorphic object models:

http://www.codesynthesis.com/projects/xsd/documentation/cxx/tree/manual/#2.11


Boris




More information about the xsd-users mailing list