Search code examples
c++xmlqtjaxbcodesynthesis

Generate XML in QT like JAXB


I generated a C++ class with CodeSynthesis from an XSD file. Now I want to create a C++ object, fill it with data and serialize it into XML or JSON format. How can i generate the XML? I also use the framework Qt. It should look like JAXB. For example (JavaCode):

Worker w = new Worker();
w.setName("Peter");
w.setStreet("...");
String xml = "XMLGenerator".generate(w);`

Is this possible?


Solution

  • Yes it is possible.

    There is a hello world example in the documentation for CodeSynthesis XSD where a C++ object is created and then being serialized into XML.

    Read more about it in:

    C++/Tree Mapping Getting Started Guide (Section 2.5 Adding Serialization)