EXTERNAL: Re: [xsd-users] Serialization Methods For Polymorphic Types

Friess, Jason jason.friess at lmco.com
Wed Oct 5 09:35:06 EDT 2011


Boris and Erik,

Thanks for your assistance with this!  I have been able to confirm that I see the behavior you both described.

What about going the other way - from XML to objects?  Can we call the parent type deserialization method with some XML (that could represent a child type) and then get a child type object instance back?...or would we always get an instance of the parent type?

Thanks!
Jason

-----Original Message-----
From: Boris Kolpackov [mailto:boris at codesynthesis.com] 
Sent: Tuesday, October 04, 2011 9:47 AM
To: Friess, Jason
Cc: xsd-users at codesynthesis.com
Subject: EXTERNAL: Re: [xsd-users] Serialization Methods For Polymorphic Types

Hi Jason,

Friess, Jason <jason.friess at lmco.com> writes:

> xml_schema::namespace_infomap map;
> std::ostringstream oss;
> Parent_(oss, obj, map); // "Parent_" would be a serialization method generated for the element associated with the parent type,
> //"obj" is an object which has a type which is one of the child types of the parent type
> std::string xml(oss.str()); //"xml" is the resulting XML string
> 
> Is this possible?  

Yes, as Erik mentioned, this works out of the box and you don't need to
do anything special.


> If so - will it result in XML that is appropriate for the child type?

Yes, if there is a substitution group element available for this child
type, then that element will be used. Otherwise, the parent element
will be used and xsi:type attribute will be added.

Boris



More information about the xsd-users mailing list