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

发布于 2024-11-03 23:41:42 字数 689 浏览 1 评论 0原文

我正在使用这个很棒的工具(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 子节点。这可以做到吗?怎样才能实现呢?

谢谢

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

枯叶蝶 2024-11-10 23:41:42

如果我明白你在问什么,我想你想使用 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}

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}
情丝乱 2024-11-10 23:41:42

是的,这是可能的。如果您希望仅序列化地址元素,则需要将 --root-element 选项传递给 CodeSynthesis XSD 命令。在 Ubuntu 中,你可以

xsdcxx cxx-tree --root-element address --generate-serialization people.xsd

这样写:如果你只需要地址的值,你可以完全跳过序列化,只使用生成的 get 函数 address()

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文