[xsd-users] Custom XSD type to C++ type mapping / performance

Boris Kolpackov boris at codesynthesis.com
Thu Feb 16 13:14:07 EST 2006


Hi,

eb.brain at gmx.net <eb.brain at gmx.net> writes:

> I have some experience with XML binding tools (JAXB / LEIF), but now I've
> found "xsd c++/tree" and I want to try it out.

Cool. Let us know how it stacks up.


> Event after reading the docs and the postings, I still have some questions:
>
> - does "xsd" provide a way to customize the type mappings?

There is no such facility in xsd at the moment mainly because we haven't
come up with something universally useful and convenient at the same time.
Here are some ideas we have so far:

1. Allow to derive from generated types and use these new types when
   constructing the tree (via a factory that is passed to the parsing
   function). This is a fairly clean but not very generic approach.

2. Allow to specify base classes for generated types (either in the
   schema or as a command-line option). This is fairly generic and
   reasonably convenient. The base classes can be either inserted
   "inline" in the generated code or included from a separate file
   using the prologue/epilogue options.

3. Allow to provide custom mapping for individual types. This is fairly
   easy to implement but will require the user to support interface
   expected by the type system (e.g., inherit from xml_schema::type base
   type (mapping for XML Schema anyType), etc.) Again the custom type
   names can be specified either directly in the schema or using command-
   line options.


>   (for example: map the XMLSchema type "xsd:dateTime" to the C++ type
> "boost::posix_time::ptime" - or event any custom C++ - class)

It is actually on our TODO list to support optional mapping of XML
Schema date/time types to types from boost's date_time library:

http://codesynthesis.com/projects/xsd/documentation/future.xhtml

I think to achieve what you want we will need to support (3) above. Note
also that you won't be able to use arbitrary C++ classes - you will have
to implement the interface expected by the type system. It shouldn't be
hard to implement (3) above so let me know if you would like to try it
out.


> - does "xsd" generate a perfect parser or just a wrapper arround a general
> XML parser (Xerces)?

Quoting from C++/Tree Mapping FAQ[1]:

"Parsers generated by xsd do not assume instance documents are valid. They
 include a number of checks that prevent construction of inconsistent in-
 memory representations. This, however, does not mean that an instance
 document that was successfully parsed by the xsd-generated parsers is
 valid per the corresponding schema."

In other words, we support two approaches: fast and compact validation
implemented in generated code which checks for basic structure but does
not handle things like key/keyref, etc. and complete validation using
Xerces-C++.


> What about the runtime performance?

Nobody complained so far ;-). I believe our validation in generated
code is as fast as it gets. For the complete validation with Xerces-C++,
there are a number of optimization techniques (like grammar pre-loading
and caching) that makes it fairly fast. I think that once the grammar
was pre-compiled the performance should be comparable to that of a
generated validator.

I believe JABX delegates validation to the generic schema validator.
You said you have experience with LEIF; does it support complete
XML Schema support in generated code? If so how's the code size and
performance?


[1] http://codesynthesis.com/projects/xsd/documentation/cxx/tree/faq/#2.3

hth,
-boris
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 652 bytes
Desc: Digital signature
Url : http://codesynthesis.com/pipermail/xsd-users/attachments/20060216/cfc661ba/attachment.pgp


More information about the xsd-users mailing list