c++ Boost循环通过未知的ptree和列表属性值
C++ Boost loop through unknown ptree and list values of attributes
我想解析包含特定属性的节点的随机xml文件,并检索该属性的所有值。用例是有许多具有不同节点的xml,但是要检索的属性总是已知的。
下面是一个文件示例:
<node>
<container>
<object attribute="value" />
<object attribute="value" />
<container/>
<supercontainer>
<subcontainer>
<otherobject attribute="value" />
<subcontainer/>
<supercontainer/>
</node>
这是我现在使用boost property_tree的内容,但我不知道在循环中该怎么做:
ptree pt;
read_xml(xml_file, pt);
BOOST_FOREACH(boost::property_tree::ptree::value_type &ele, pt)
{
//NO IDEA
}
想法欢迎。
谢谢
好的,我用下面的方法解决了这个问题:
void recurseManifest(ptree &pt, int lvl)
{
for (ptree::iterator current = pt.begin(); current != pt.end();)
{
try
{
std::cout << current->second.get<std::string>("<xmlattr>.attribute") << std::endl;
}
catch(const boost::property_tree::ptree_bad_path &err)
{
std::cerr << err.what() << std::endl;
}
assets = recurseManifest(current->second, lvl++);
++current;
}
}
相关文章:
- Pybind11:将元组列表从Python传递到C++
- 从链接列表c++中删除一个项目
- 如何(从固定列表中)选择一个数字序列,该序列将与目标数字相加
- C++如何通过用户输入删除列表元素
- 读取文件的最后一行并输入到链接列表时出错
- 复制列表初始化的隐式转换的等级是多少
- LNK2038、MSVS2017 MAGMA的原因列表
- 不能在初始值设定项列表中将非常量表达式从类型 'int' 缩小到'unsigned long long'
- 没有为自己的结构调用列表推回方法
- 使用简单类型列表实现的指数编译时间.为什么
- 一对向量构造函数:初始值设定项列表与显式构造
- 标准是否使用多余的大括号(例如 T{{{10}}})定义列表初始化?
- 通过for循环使用用户输入填充列表
- C++:如何使函数只返回作为列表一部分的字符串
- 概念中的cv限定符需要表达式参数列表
- 下面是我为检测链接列表中的循环而制作的代码
- 建议在运行时将带有类实例的列表从c++导入qml
- 如何维护资源管理器项目视图中当前可见的项目列表
- 在卡萨布兰卡形成编码参数的列表
- c++ Boost循环通过未知的ptree和列表属性值