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

How to write an XML file from an XSD cxx tree object?

本文关键字:XML 文件 对象 XSD cxx      更新时间:2023-10-16

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

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

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

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

最好的方法是什么?

似乎将 --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();

工程。参考:从 XSD 指南中添加序列化和详细信息。