如何从XSD cxx树对象编写XML文件?

时间:2012-04-11 08:56:46

标签: c++ xml xsd xerces-c codesynthesis

我正在使用一个使用XSD从C ++中基于XML的格式创建对象的库。

基本上,继承图看起来像这样:

class BaseClass: public xsd::cxx::tree::type;
class MainXmlObject: public BaseClass;

我想我需要将MainXmlObject转换为xerces::DOMDocument然后使用DOMWriter来编写实际的XML文件,但到目前为止我找不到合适的例程。 / p>

这样做的最佳方式是什么?

1 个答案:

答案 0 :(得分:0)

似乎将--add-serialization标志添加到xsd代码生成中,然后使用类似的内容:

xml_schema::namespace_infomap map;
//    map[""].name = "test"; // xmlns
//    map[""].schema = "http://sbgn.org/libsbgn/0.2"; // xsi:noNamespaceSchemaLocation
ofstream ofs(fname.c_str());
sbgn_(ofs, s, map); // invoking the stream here
ofs.close();

的工作原理。参考文献:Adding serialization中的detailsXSD guide