gpt4 book ai didi

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

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:48:07 25 4
gpt4 key购买 nike

我正在使用这个很棒的工具 (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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com