[xsd-users] Serialization of Polymorphic Sequences

Friess, Jason jason.friess at lmco.com
Tue Sep 20 17:14:44 EDT 2011


Hi,

We are using CodeSynthesis XSD to generate C++ code from a set of XSD's that we have created and we have run into a potential issue.  Several of the complexTypes defined in our schemas include polymorphic sequences.  We have defined some sequences as sequences of some parent type but we would like to put child type instances in them.  In our tests we have been able to put pointers to child type instances in the sequences - but when we serialize to XML the resulting XML does not seem to reflect the child instances.

Is there something we are doing wrong?

Thanks!
Jason

Example Code:
// create a MessageType object from XML string - this works!
std::istringstream iss (xml);
auto_ptr<MessageType> mfs (Message (iss));

// create a ChildType object (subclass of ParentType) - this works!
auto_ptr<ParentType> pt(new ChildType());

// add ChildType to MessageType Payload sequence - this works!
mfs->Payload().push_back(pt);

cout << endl << "-------------------------------------" << endl
        << "Message with ChildType payload ";

// verify that element 0 is a ChildType - this works! - prints "valid derived pointer"
ChildType *e0 = dynamic_cast<ChildType*>(&mfs->Payload()[0]);
if (e0)
        cout << "(valid derived pointer)" << endl << endl;
else
        cout << "(invalid derived pointer)" << endl << endl;

// display XML of modified MessageType object - this does not work! - the XML printed here does not reflect the ChildType instance - only that a ParentType has been included
Message (cout, *mfs, map);


More information about the xsd-users mailing list