c++ - 代码综合——C++/Tree子节点序列化

标签 c++ tree mapping codesynthesis

我正在使用这个很棒的工具 (http://www.codesynthesis.com/products/xsd/c++/tree/) 将 xsd 转换为 C++ 代码。

我试图从子节点获取 xml 字符串,但我唯一能得到的是所有 xml,如下所示:

所有的xml:

<?xml version="1.0"?>
<people ....>

  <person id="1">
    <first-name>John</first-name>
    <address>
      ....
    </address>
  </person>
...

我可以让所有的 xml 做这样的事情:

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

但我想要的是仅获取

xml 子节点。这有可能吗?如何实现?

谢谢

最佳答案

如果我理解您的问题,我认为您想要使用 no_xml_declaration 标志。

people (oss, p, map, "UTF-8",
        xml_schema::flags::no_xml_declaration);

这会抑制 XML 声明,但对于某些版本的 Xerces-C,它会在开头产生一个虚假的换行符,您需要将其删除。 http://www.codesynthesis.com/pipermail/xsd-users/2009-December/002625.html

对于以后引用此问题的任何其他人,您还需要使用 --generate-serialization 调用 xsdcxx。默认情况下仅发出解析方法。

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

关于c++ - 代码综合——C++/Tree子节点序列化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5843780/

相关文章:

c++ - 尝试对结构 A-Z 文件进行排序时出现排序函数错误

Java二叉搜索树——插入实现

javascript - Radial Reingold Tilford Tree 删除根节点

mapping - 没有注释的 JACKSON 映射 XML 配置

c++ - 为什么包含-fPIC 编译静态库会导致运行时出现段错误?

c++ - 展开多维数组指针失败c++

c++ - 无法使用 KDevelop 设置 vcpkg CMAKE_TOOLCHAIN_FILE

algorithm - 成绩较好但jee排名较低的学生人数

mysql - 一对多双向映射提示没有默认值错误

javascript 迭代和重新映射