6

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

Nuno
  • 1,910
  • 2
  • 21
  • 33
  • guess that is not possible... – Nuno May 02 '11 at 14:32
  • I wouldn't jump to a conclusion. Not many people have looked at your question, and it is hard to believe somebody would go an build a tool for working with XML with making the elements of the XML tree somehow accessible. So, there may still be answer you just haven't heard. BTW, if this is a commercial product, doesn't it have a reference manual, and what does that manual say? – Ira Baxter May 03 '11 at 23:34

2 Answers2

0

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()

Erik Sjölund
  • 10,690
  • 7
  • 46
  • 74
0

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}
DGentry
  • 16,111
  • 8
  • 50
  • 66