我想知道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?
参见上面的第一个链接:)
也可以看看:
关于c++ - 使用Boost PTree w/o标签解析XML,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63136333/