[xsd-users] xs:choice representation in C++

Boris Kolpackov boris at codesynthesis.com
Tue Oct 13 11:05:09 EDT 2009


Hi Ray,

I've CC'ed xsd-users in case someone else is also has to handle something 
like this.

Ray Lischner <rlischner at proteuseng.com> writes:

> > Well, in this specific case, order for "to", "cc" and "bcc" elements is
> > obviously not important. Most cases that I have seen would fall into
> > this category.
>
> I don't know what most cases are, but I know for us, this particular 
> issue causes no small amount of pain. We have a list of choice of lists,
> and the order is significant. Although we use and love Code Synthesis 
> elsewhere in the project, we cannot use Code Synthesis for this part.
> Currently, we have a Java class handling this part of the project, but
> there are plans to replace the Java class with C++, and I pity the 
> unfortunate who will not be able to use Code Synthesis.

If it is a small part of the vocabulary (e.g., one or two types use this 
construct), then there are a couple of options that you can consider:

1. You can customize the type by providing an interface that preserves
   the order. While this will require you to do manual parsing for such
   types, the bulk of the vocabulary can still be handled automatically.

2. You can turn on the DOM association feature and traverse the content 
   in the "document order" instead of the "object model order". Because
   you can go back from a DOM node to the corresponding object model node,
   you can still use the object model to actually access the data. That
   is, the DOM interface is only used for navigation in places where
   order is important.

3. You can customize xml_schema::type (base class for all the generated
   and built-in type) to include a "total order" counter (i.e., increment
   it every time a new object is created). This way all the nodes in the 
   object model will have "parsing order" information.

4. If you can modify the schema then there is an elegant way to get rid
   of choice's altogether. This approach is described in detail in this 
   post:

   http://www.codesynthesis.com/pipermail/xsd-users/2008-May/001697.html

On the other hand, if the use of choice and the requirement to preserve 
order is spread throughout your schema then the only option I have is to
use XSD/e and the C++/Hybird mapping:

http://www.codesynthesis.com/products/xsde/

This mapping provides precise reproduction of XML vocabulary structure 
and element order in the object model.


Boris



More information about the xsd-users mailing list