Code Synthesis - C++/Tree sub node serialization

1.6k views Asked by At

I'm using this great tool (http://www.codesynthesis.com/products/xsd/c++/tree/) to convert xsd into c++ code.

I'm trying to obtain the xml string from a sub node, but the only thing that i can get is the all xml, like this:

the all xml:

<?xml version="1.0"?>
<people ....>

  <person id="1">
    <first-name>John</first-name>
    <address>
      ....
    </address>
  </person>
...

I can get the all xml doing something like this:

people_t& p = ...
xml_schema::namespace_infomap map;
map[""].schema = "people.xsd";

// Serialize to a string.
//
std::ostringstream oss;
people (oss, p, map);
std::string xml (oss.str ());

But what i want is to get only the < address > xml sub node for example. This is possible to do? how can be accomplished?

Thanks

2

There are 2 answers

0
DGentry On

If I understand what you're asking, I think you want to use the no_xml_declaration flag.

people (oss, p, map, "UTF-8",
        xml_schema::flags::no_xml_declaration);

This suppresses the XML declaration, though for some versions of Xerces-C it results in a spurious newline at the beginning which you'll need to remove. http://www.codesynthesis.com/pipermail/xsd-users/2009-December/002625.html

For anyone else referencing this question later, you also need to invoke xsdcxx with --generate-serialization. By default only parse methods are emitted.

xsdcxx cxx-tree --generate-serialization {source XSD files}
0
Erik Sjölund On

Yes, it is possible. If you want to be able to serialize only the address element, you need to pass the --root-element option to the CodeSynthesis XSD command. In Ubuntu you would write

xsdcxx cxx-tree --root-element address --generate-serialization people.xsd

If you on the other hand just need to the value of the address, you could skip serialization altogether and just use the generated get function address()