gpt4 book ai didi

c++ boost xml解析器ptree.get函数——不接受节点名称中的空格

转载 作者:塔克拉玛干 更新时间:2023-11-03 07:16:41 24 4
gpt4 key购买 nike

尝试使用 C++ 使用 boost xml 解析器从 xml 文件中获取内容..

opencv.xml

<opencv_storage>
<labels type_id="opencv-matrix">
<data>0 0 0 0 1 1 0 0</data>
</labels>
</opencv_storage>

C++ 代码片段

using boost::property_tree::ptree;
ptree pt;
boost::property_tree::read_xml("opencv.xml", pt);

std::string m_file = pt.get<std::string>("opencv_storage.labels type_id=\"opencv-matrix\".data");

std::cout<<"m_file "<<m_file<<std::endl;

程序执行时抛出异常:

No such node (opencv_storage.labels type_id="opencv-matrix".data)

我怀疑,标签和 type_id 之间是否存在空格

在此先感谢,任何帮助将不胜感激,因为我正在努力习惯 boost 。

最佳答案

当然不是。元素名称中的空格在 XML 中是非法的。

你真正想要的是属性:Parsing XML Attributes with Boost

或者,更好的是,您想使用 XML 解析器,此处:What XML parser should I use in C++?


如果您想以某种方式使用 poperty 树(您确定吗?)看这里:

enumerate-path 函数显然也可以用于 XML,因为它需要一个 ptree

关于c++ boost xml解析器ptree.get函数——不接受节点名称中的空格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32690187/

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