[xsd-users] Code Synthesis use question

Boris Kolpackov boris at codesynthesis.com
Wed Jul 16 11:32:05 EDT 2008


Hi Bryan,

In the future please keep your replies CC'ed to the xsd-users mailing
list. This way other developers who may have experienced a similar
problem can provide you with a solution. Plus questions and answers
will be archived and available to others with similar problems.

Bryan Wilcox <azbwilcox at yahoo.com> writes:

> One more quick clarification if you have the time.  
>  
> The issue has to do with this generated code below.  
>     typedef ::axm::Definition definition_type;
>     /**
>      * @brief Element sequence container type.
>      */
>     typedef ::xsd::cxx::tree::sequence< definition_type > definition_sequence;
> ...
>     protected:
>     definition_sequence definition_;
> 
> and axm::Defintion is a base class for a number of derived classes any
> of which can be inserted into the defintion_sequence defintion_.  If I
> am iterating over the container defintion_, what is the type of the
> sequence iterator?  Does it work like std::library iterators where
> definition_sequence::const_iterator is an iterator and * of this
> would give you an object reference into the container of type
> defintion_type?  Or using the -> operator on the sequence will also
> allow you to access the underlying defintion_type reference? 
> Furthermore, since defintion_type is a base class, will 
> dynamic_cast<dervied_defintion_type>( &(*theDefItr) ) give me a
> pointer to a derived view of the object the iterator is on? 
> I believe that this is the case but wasn't sure where the best
> place to find documentation on how to use the sequence container was.

Ok, you seem to be using XML Schema polymorphism in the form of xsi:type
or substitution groups and this is one of those few cases where it makes
sense to use xsd:anySimpleType as an abstract base. 

If you compile your schemas with the --generate-polymorphic option then
the assumptions you outlined above are correct: the sequence will contain
objects of varying dynamic types and you will be able to discover their
types at runtime using, for example, dynamic_cast. This is all discussed
in more detail and with examples in Section 2.11, "Mapping for xsi:type
and Substitution Groups" of the C++/Tree Mapping User Manual:

http://www.codesynthesis.com/projects/xsd/documentation/cxx/tree/manual/#2.11

If you are not using xsi:type-based dynamic typing or substitution groups
then we will need to see the relevant parts of your schema and XML document
to better understand what you are trying to achieve.

Boris




More information about the xsd-users mailing list