I want to remove a node from a ptree which is based on xml:
<library>
<booklist>
<book id="10">
<data title="t1"/>
</book>
<book id="10">
<data title="t2"/>
</book>
<book id="10">
<data title="t3"/>
</book>
<book id="20">
<data title="t4"/>
</book>
</booklist>
</library>
I have an algorithm to find the right node which returns a pointer to the removing node. Also I have a pointer to the parent of the removing node. but the erase() will take an iterator (not a pointer). My question is how to remove the node using two pointers; a poiter to the removing node and another to the parent node.
void removeElement(const std::string addr, const std::string criteria, boost::property_tree::ptree &ptSource)
{
boost::property_tree::ptree *ptParent = findParentPTree(addr, criteria, ptSource); // Points to "library.booklist"
boost::property_tree::ptree *ptRemove = findRemovePTree(addr, criteria, ptSource); // eg the third <book> which contains the <data title="t3"/>
// question: how to remove node ptRemove from ptSource?
}
Note that there are some examples using iterators, but it is not clear how should the iterator of removing node be found.