[xsd-users] type inheritance/substitution and generated class
interface
Boris Kolpackov
boris at codesynthesis.com
Wed Dec 2 08:31:57 EST 2009
Hi Sumant,
Sumant Tambe <sutambe at dre.vanderbilt.edu> writes:
> 1. Once the XML is parsed and and in-memory object model is created, how
> do I downcast from base to derived type? Specifically from the example,
> how do I know that a Person is in fact a Superman and get a Superman
> type of object from the Person object. I tried dynamic_cast thinking
> that person object reference might be polymorphic, but it does not seem
> to work.
The two most common reasons why this does not work are:
1. You haven't compiled your schemas with the --generate-polymorphic
option.
2. You have made a "sliced" copy of the object model node. When dealing
with polymorphic object models you should use references or make
complete copies using the _clone() function.
For more information see Section 2.11, "Mapping for xsi:type and Substitution
Groups" in the C++/Tree Mapping User Manual:
http://www.codesynthesis.com/projects/xsd/documentation/cxx/tree/manual/#2.11
As well as the polymorphism example in th examples/cxx/tree/ directory.
> 2. Does substitutionGroup have any effect on the generated class
> interface?
No, substitution groups are handled automatically by the generated
code. Unless you use DOM, there is way to tell whether xsi:type or
the substitution groups mechanism was used to provide the dynamic
type.
Boris
More information about the xsd-users
mailing list