c++ - 使用Boost PTree w/o标签解析XML

标签 c++ visual-studio boost xml-parsing ptree

我想知道Boost Ptree是否允许在不知道属性标签的情况下解析.xml文件。我有一个XML文件,该文件会定期更新为新标签,新数据,甚至删除某些标签。这些常规更改促使我开始考虑在不对属性名称进行硬编码的情况下分析文件。有什么方法可以在不说明标签名称的情况下读取XML文件中的所有数据?任何帮助表示赞赏!

最佳答案

Ptrees aren't ideal for parsing XML but Boost is so integrated into the rest of my project that it would be incredibly taxing to use libxml2 or another parser


对不起,那没有道理。
有仅 header 的选项,以及很多重量很轻的选项。参见What XML parser should I use in C++?
由于Boost Property Tree显然不是库,因此,与需要解决的抽象抽象和不可能实现的成本相比,添加库的感知成本将远远超过。

And it seems like I do have to state the tag name when I use read_xml. There doesn't seem to be a way that I can read all the child nodes underneath a parent node and store them.


干得好:
#include <boost/property_tree/xml_parser.hpp>

int main() {
    boost::property_tree::ptree pt;
    std::ifstream ifs("input.xml");

    read_xml(ifs, pt);
    write_xml(std::cout, pt);
}

I've also read through the boost documentation but couldn't seem to find anything.


我将从这里开始:https://www.boost.org/doc/libs/1_73_0/doc/html/property_tree/parsers.html#property_tree.parsers.xml_parser。关注限制。并非所有限制都明确存在(请参阅RadidXML文档)。

Do you know how boost get child nodes or other c++ parsers I could look at?


参见上面的第一个链接:)
也可以看看:
  • 在我的答案中搜索"not an xml library"
  • 任何Property Tree answers using XML的Ditto(请注意,我们从未指定要读取的节点),因为这根本不可能。许多答案详细说明了如何通过一些动态路径查找节点,如果那是您真正在寻找的
  • 我的一些answers that use PugiXML-其中大多数是针对Boost属性树无法处理的问题
  • 其他一些库TinyXMLRapidXML只是为了了解它们何时合适/不错
  • 关于c++ - 使用Boost PTree w/o标签解析XML,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63136333/

    相关文章:

    C++ 错误 : identifier "CWnd" is not defined

    c++ - C 和 C++ 中的字符串输入

    c++ - 向 MPI 进程发送函数

    asp.net - 重新编译asp.net网站时如何重新启动IIS站点

    git - Visual Studio Online - 无法解析版本描述符 <BranchName>

    python - 使用 pip install : Required library boost not found 时

    c++ - 错误已定义

    visual-studio - VS 2013 TypeScript 支持不起作用

    c++ - Visual Studio 2010,有什么方法可以添加前缀,例如(C :\) to #include a massive amount of <boost/asio. hpp> 标题?

    c++ - 编译器在 Boost::ASIO 写入和 unistd 写入之间混合