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

Bill Pringlemeir bpringle at sympatico.ca
Wed Sep 30 13:53:07 EDT 2009


On 28 Sep 2009, leonid.gershanovich at 247realmedia.com wrote:

> I do believe that there are two separate scenarios:
> a. developer is given a schema
> b. developer designs schema as well as C++ code

[snip]

> However, in second case, I cannot imagine why developer might want
> to have flatten representation in c++ code, after all, developer can
> always make his schema in such a way that c++ code is simpler.  In
> other words - in my opinion, schema is yet another way to express
> data model/structure, and when I, as a developer, elect to create
> complicated schema, than I want my c++ data model to mimic that,
> otherwise I would have created a simpler schema.

If you really like this boost::variant, then you can setup XSD to
create custom classes for your schema.  The only thing that XSD needs
is implementations of,

 constructors, destructors, _clone, [and possibly a friend serialize()?]

You can completely re-write the accessors and implementation as long
as you have this API.  Obviously this is not automatically generated.
However, if you have multiple recurrences of this 'xs:choice', you
could wrap it in a base class and/or template for re-use.

Consider that many people might not be using boost.  This *might* be a
nice feature to have for some users.  I think that the XSD development
is best spent on features that are useful for all users.

I have finished using XSD on a project like case b.  The upfront
analysis of the common data items to create an object repository that
includes custom methods for the C++ domain made many things work more
smoothly.  Writing custom classes means you *dont* have to wait for
another release of XSD.  I am quite sure you can create a custom class
that has the C++ API that you want.  It all depends on whether you
have a time budget to implement this.  For some cases, doing this up
front may actually save time.

http://wiki.codesynthesis.com/Tree/Customization_guide#Customizing_the_XML_Schema_built-in_types

I am sure that Boris can probably give some good guidance on how to
achieve this?

Fwiw,
Bill Pringlemeir.




More information about the xsd-users mailing list