【问题标题】:How to write an XML file from an XSD cxx tree object?如何从 XSD cxx 树对象写入 XML 文件?
【发布时间】:2012-04-11 08:56:46
【问题描述】:

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

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

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

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

最好的方法是什么?

【问题讨论】:

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


    【解决方案1】:

    似乎将--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 serializationdetails 来自 XSD guide

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-03-29
      • 1970-01-01
      • 1970-01-01
      • 2015-09-09
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多