Code Synthesis - C ++ / Tree node serialization

I use this great tool (http://www.codesynthesis.com/products/xsd/c++/tree/) to convert xsd to C ++ code.

I am trying to get an xml string from under node, but the only thing I can get is all xml, for example:

all xml:

<?xml version="1.0"?> <people ....> <person id="1"> <first-name>John</first-name> <address> .... </address> </person> ... 

I can get all xml to do 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 I want to get only <addresses> xml sub node, for example. It can be done? How can I do that?

thanks

+6
source share
2 answers

If I understand what you are 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, although for some versions of Xerces-C this results in a false new line at the beginning that you will need to delete. http://www.codesynthesis.com/pipermail/xsd-users/2009-December/002625.html

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

 xsdcxx cxx-tree --generate-serialization {source XSD files} 
0
source

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

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

If you, on the other hand, just need an address value, you can skip serializing altogether and just use the generated get address() function

0
source

Source: https://habr.com/ru/post/887022/


All Articles