[xsd-users] How can I put the attribute xsi:type="DataDocument" in the root node?

Boris Kolpackov boris at codesynthesis.com
Wed Apr 13 12:36:04 EDT 2011


Hi Roberto,

I've discarded your second post with a 24MB attachment. Please read
the posting guidelines for more information on how to send code to
the mailing list:

http://www.codesynthesis.com/support/posting-guidelines.xhtml


Roberto Escobar <rescobar at datatec-ec.com> writes:

> auto_ptr<Document> doc(FpML("xml_swap.xml"));
> 
>  
> Document document(*doc);
>
> [...] 
>
> Now,  as I need to manipulate the object "DataDocument" instead
> "Document", I do the cast, but this return null.

Making a copy of a polymorphic object model is a bad idea. What
happens here is you "slice" the object and loose all the dynamic
type information. Instead you should always use references (and
_clone() of you really need to make a copy):

Document& document (*doc);
 

> Since I had this problem then I created new functions, which I will
> return the DataDocument instead Document based on FpML functions. These
> functions work well. But in the header would have to be "xsi: type =
> DataDocument", but not shown this, it is because I am showing the Object
> DataDocument, so my question is whether it is possible to put this
> attribute in the header.

You should use the FpML() functions for serialization. If your
document is not "sliced", you should get the xsi:type attribute
automatically.

Boris



More information about the xsd-users mailing list