[xsd-users] How to build an object process graph with custom types
Florian Paul Schmidt
fschmidt at techfak.uni-bielefeld.de
Wed May 11 15:24:52 EDT 2011
On 05/11/2011 11:26 PM, Boris Kolpackov wrote:
> Hi,
>
> Bo Ba<bo-ba at mail.ru> writes:
>
>> This seems to be doable, however, a specific question I have whether
>> it would be feasible to skip building the DOM structure and directly
>> build my custom object graph using xsd.
> Yes, the C++/Parser mapping is designed for exactly this: parsing XML
> and building a custom in-memory representation:
>
> http://www.codesynthesis.com/products/xsd/c++/parser/
>
> Boris
>
Hi folks,
maybe i totally missed something, but oftentimes you have another step
involved: Building the requested datastructure from the custom in-memory
representation of the XML document. For my robotics control "framework"
I chose a way of using a global "type registry" which enables me to
construct and parametrize the objects needed..
The software is available at github:
http://github.com/fps/CBF
Especially of interest to you might be the xml_object_factory.h:
https://github.com/fps/CBF/blob/master/libcbf/cbf/xml_object_factory.h
Note that for this to work, every type you want to construct from a
corresponding XML schema type needs a constructor that takes the
corresponding schema type as argument:
https://github.com/fps/CBF/blob/master/libcbf/cbf/linear_transform.h
Also each type has to create a static global instance of the derived
factory type in its .cc file, so at library (or application) load time
this instance is created and registers itself with the base factory
singleton:
https://github.com/fps/CBF/blob/master/libcbf/linear_transform.cc
This then allows constructed objects to construct its members in turn
again using this mechanism. See e.g. lines 259ff here:
https://github.com/fps/CBF/blob/master/libcbf/primitive_controller.cc
The corresponding schema can be found here:
https://github.com/fps/CBF/blob/master/schemas/schemas.xsd
Maybe this helps, or maybe it's totally misleading cause i'm a dumba**
:D I guess the idea is generic enough to be factored out into a library
on its own..
Have fun and play safe,
Flo
More information about the xsd-users
mailing list