代码综合-C++/Tree子节点序列化
我正在使用这个很棒的工具(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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果我明白你在问什么,我想你想使用 no_xml_declaration 标志。
这会抑制 XML 声明,但对于 Xerces-C 的某些版本,它会在开头产生一个虚假的换行符,您需要将其删除。
http://www.codesynthesis.com/pipermail/xsd-users /2009-December/002625.html
对于稍后引用此问题的其他人,您还需要使用 --generate-serialization 调用 xsdcxx。默认情况下仅发出解析方法。
If I understand what you're asking, I think you want to use the no_xml_declaration flag.
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.
是的,这是可能的。如果您希望仅序列化地址元素,则需要将
--root-element
选项传递给 CodeSynthesis XSD 命令。在 Ubuntu 中,你可以这样写:如果你只需要地址的值,你可以完全跳过序列化,只使用生成的 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 writeIf 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()