使用Boost PTree w/o标签解析XML [英] Parsing XML's with Boost PTree w/o tags

查看:113
本文介绍了使用Boost PTree w/o标签解析XML的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I would like to know if Boost Ptree allows parsing .xml files without having the attribute tags known. I have an XML file that will regularly be updated with new tags, new data, and even remove certain tags. These regular changes prompted me to look into parsing the file without hardcoding the attribute name. Is there any way I can read all the data in the XML file without stating the tag name? Any help is appreciated!

推荐答案

Ptrees不是解析XML的理想选择,但Boost已集成到我的项目的其余部分中,以至于使用libxml2或其他解析器会让人难以置信

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

对不起,那没有道理.

有仅标头选项,以及很多非常轻量级的选项.请参见我应该在C ++中使用哪种XML解析器?

There are header-only options, and a good number of very light-weight options. See What XML parser should I use in C++?

由于Boost属性树很简单并且显然不是您需要的库,因此与解决破碎的抽象和不可能实现的成本相比,添加库的感知成本将远远超过./p>

Since Boost Property Tree is simply and clearly not the library you need the perceived cost of adding a library will be far outweighed by the cost of battling the broken abstractions and impossibilities that you will encounter.

当我使用read_xml时,似乎必须声明标签名称.似乎没有一种方法可以读取父节点下的所有子节点并将其存储.

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

我也已经阅读了Boost文档,但似乎找不到任何东西.

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

我将从这里开始:

I'd start here: https://www.boost.org/doc/libs/1_73_0/doc/html/property_tree/parsers.html#property_tree.parsers.xml_parser. Focus on the limitations. Not all limitations are explicit there (see documentation for RadidXML).

您知道我如何看待boost如何获得子节点或其他c ++解析器吗?

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

请参阅上面的第一个链接:)

See first link above :)

另请参阅:

  • Search my answers for "not an xml library"
  • Ditto for any Property Tree answers using XML - note that we never specify what node to read - because that's simply not possible. Many answers detail how to find nodes by some dynamic path, though, if that's what you're really looking for
  • Some of my answers that use PugiXML - the majority of which are in response to questions that couldn't be handled with Boost Property Tree
  • Some other libraries TinyXML, RapidXML, just to get a taste of when they are suitable/nice or not

这篇关于使用Boost PTree w/o标签解析XML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆