C++ Object to XML for communication
c++, serialization, xml, xml-serialization
Solution
What you describe is referred to as XML Data Binding. There are a number of products that will generate the C++ code from and XSD or DTD, have a look at http://www.xmldatabinding.org/ for a list, and http://www.rpbourret.com/xml/XMLDataBinding.htm for more information.
Also have a look at this XML Data Binding example for C++, it shows the example source schema and generated code.
If your schemas are pretty basic and you have the ability to tune them to the generator then there are probably some open source projects that will do the job. If you are binding to an XML Standard then you quickly run up against the limitations of most generators. The Liquid XML generator copes with pretty much all XSD standards, but you have to pay for it.
Problem
I'm looking for a simple-way to transform in C++ an object into XML string representation, so this way I could communicate with a server. For instance, let us say I have an object: ``` class A{ string data1; string data2; string dataN; list<B> bList; } class B{ string moreData; } ``` I would like the following XML-representation: (Assume that I have created one instance A and it has two instances of B) ``` <A> <data1>content</data1> <data2>content</data2> <dataN>content</dataN> <B> <moreData>content</moreData> </B> <B> <moreData>content</moreData> </B> </A> ```