[英]iterate over boost::property_tree XML
如果我对设置结构一无所知,该如何遍历boost :: property_tree(XML部分)?
我想知道所有字段的名称和xmlattr名称。
我没有在该库的boost文档中看到这样的示例。
在此处查看升压文档。 在页面的下方,您可以看到以下示例代码:
// Iterate over the debug.modules section and store all found
// modules in the m_modules set. The get_child() function
// returns a reference to the child at the specified path; if
// there is no such child, it throws. Property tree iterators
// are models of BidirectionalIterator.
BOOST_FOREACH(ptree::value_type &v,
pt.get_child("debug.modules"))
m_modules.insert(v.second.data());
只需修改代码即可遍历您的根属性树中的所有模块(并根据需要递归到子树中)。
因此,例如:
ptree my_tree;
// Read in your XML to the tree
...
BOOST_FOREACH(ptree::value_type &v,
pt, do_something_with_field(v.second.data());
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.