[xsd-users] problem with polymorphic dynamic cast

Boris Kolpackov boris at codesynthesis.com
Thu Jul 1 06:11:06 EDT 2010


Hi John,

Dingelstad, John <john.dingelstad at dhv.com> writes:
 
> I'll used the option -generetate-polymorphic along with version 3.3.

The DATEXII schema uses xsi:type to specify dynamic types. When you
use the --generate-polymorphic option, the XSD compiler will auto-
detect types that are used in substitution groups and treat them as
polymorphic. However, if the vocabulary uses the xsi:type approach,
the XSD compiler has no way of knowing which types are potentially
polymorphic.

There are two ways to resolve this. You can explicitly specify the 
bases of polymorphic type hierarchies with the --polymorphic-type
option. Alternatively, you can specify that all types should be
treated as polymorphic with the --polymorphic-type-all option.
The former approach is preferable since it results in smaller and
faster generated code.

For more information on this 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

For the DATEXII schema, it appears that the polymorphic type hierarchies
start with abstract types (types that have abstract="true" attribute).
To make your example work using the former approach I added the following
options to the XSD command line:

--polymorphic-type PayloadPublication
--polymorphic-type Location
--polymorphic-type AlertCPoint

I also tried the --polymorphic-type-all options and it works fine as
well.

If you are going to use the --polymorphic-type approach, then it may be
tidier to place the options in a file and then use the --options-file
option to include them into the command line (see the XSD Compiler 
Command Line Manual for details).
 
Boris



More information about the xsd-users mailing list