c++ - Boost property tree: Remove a nested node -
suppose have following tree:
boost::property_tree::ptree tree; tree.add("1.2.3", "value-1"); tree.add("1.2.3.4", "nested-value"); tree.add("1.2.3", "value-2"); tree.add("1.2.33", "other-value");
which has following serialized info form:
1 { 2 { 3 value-1 { 4 nested-value } 3 value-2 33 other-value } }
is there method remove nodes having provided (possibly nested) path? i.e.:
remove(tree, "1.2.3"); boost_assert(!tree.get_optional<std::string>("1.2.3") && !tree.get_child_optional("1.2.3"));
with result info form:
1 { 2 { 33 other-value } }
looking @ ptree docs , source code i've found several methods remove immediate children of tree (nested children not accounted). also, there several methods subtree it's full path (even if nested). since there no way node's parent, not combine these need.
is there easy way need, possibly w/o need reimplement tree traversal?
i don't think can done. kind-a ok in json, info subtree keys can repeated @ each level, making important traverse of tree
perhaps answer helps started: how iterate on xml structure in boost::property_tree
be very careful iterating tree that's being modified, though. want double check iterator invalidation rules in documentation erase
Comments
Post a Comment