[xsd-users] request for guidance

Boris Kolpackov boris at codesynthesis.com
Mon Oct 1 05:31:45 EDT 2007


Hi Ganesh,

Borse, Ganesh <ganesh.borse at credit-suisse.com> writes:

> class orderCategory {
>          pubilc:
>            orderCategory(){};
>            orderCategory(int minOrderQty, float minOrderValue):_minQty(minOrderQty), _minValue(minOrderValue)
>            {  }
>            bool isOrderSmall(int orderQty, float orderValue)
>            {
>                 if ( (orderQty < _minQty) || (orderValue < _minValue){
>                      return true;
>                 }
>                 return false;
>            }
>         private:
>            int _minQty;
>            flaot _minValue;
> };
>
> The possible XML which I want to transform into this C++ class could be
> as below:
>
> <ruleCategory>
>     <category genre="orderSizeCategory" type=SMALL>
>         <title>SMALL ORDER</title>
>         <FunctionName>isOrderSmall</FunctionName>
>         <FunctionBody>if((Qty < _minQty) OR (Value < _minValue)){ return true; } return false;</FunctionBody>
>         </if-clause>
>     </category>
> </ruleCategory>

I am having a hard time finding any correspondence between the above
class and XML fragment.


> But, instead I'm trying to generate an independent class from XML
> which then can be used for totally different purpose than just
> reading the XML document.

The C++/Tree mapping works the other way around: you give it your
XML vocabulary specification (in XML Schema) and it generates you
C++ classes (collectively called vocabulary object model) that you
can use to read, access/modify, and write data stored in XML.

The generated object model can be used for other purposes, for
example binary serialization. You can also go a step further
and customize the generated classes by adding your application-
specific logic (for example the isOrderSmall() function from
above). In this approach you will treat the generated C++
classes as base types (that simply provide data storage and
XML reading/writing functionality) for your own classes which
provide application-specific functionality.

For more information on how to customize the object mode, see
the 'contacts' example in the examples/cxx/tree/custom directory
in the XSD distribution. This example adds the print() function
to the generated class. For the general information on how to
customize the generated code see the C++/Tree Mapping Customization
Guide:

http://wiki.codesynthesis.com/Tree/Customization_guide

Alternatively, you can use the C++/Parser mapping. This mapping
allows you to parser XML and build an object model from your own
types. For an introduction to this mapping, see the C++/Parser
Mapping Getting Started Guide:

http://codesynthesis.com/projects/xsd/documentation/cxx/parser/guide/

Boris




More information about the xsd-users mailing list