Reputation: 21
Based on the boost documentation here:
http://www.boost.org/doc/libs/1_41_0/doc/html/boost_propertytree/container.html
"There may be multiple children with the same key value in a node. However, these children are not necessarily sequential. The iterator returned by find may refer to any of these, and there are no guarantees about the relative position of the other equally named children."
Sample XML:
<library>
<book><title>Title_1</title></book>
<book><title>Title_2</title></book>
<book><title>Title_3</title></book>
</library>
Sample boost code:
ptree pt;
pt.push_back(ptree::value_type("book", ptree("title")))
// This finds the first book and cannot iterate to the second one:
ptree::const_iterator it = pt.find("book");
So knowing that, how would you get all the books and be sure you go them all?
Upvotes: 2
Views: 1983
Reputation: 29021
You have to use the equal_range
function:
std::pair < ptree::const_assoc_iterator, ptree::const_assoc_iterator> bounds =
pt.equal_range("book");
for (ptree::const_assoc_iterator it = bounds.first; it != bounds.second ; ++it)
{
// process *it
}
Upvotes: 4