c++ - How to rename node/element in boost property tree? -
for example have boost property tree of following structure (created reading stream xml or in different way):
<a> <b> <c></c> </b> </a> how rename in existing tree element b new element new key: n. invoking write_xml of fixed tree should give new xml structure:
<a> <n> <c></c> </n> </a> please present code if possible or explain why not. remark: attaching subtree under c newly generated root acceptable direct renaming in priority.
well, then, possible. send check code
#include <boost/property_tree/ptree.hpp> #include <boost/property_tree/xml_parser.hpp> #include <iostream> using boost::property_tree::ptree; int main() { std::istringstream iss(r"(<a><b><c></c></b></a>)"); ptree pt; read_xml(iss, pt); pt.add_child("a.n", pt.get_child("a.b")); pt.get_child("a").erase("b"); write_xml(std::cout, pt); } prints
<?xml version="1.0" encoding="utf-8"?> <a><n><c/></n></a>
Comments
Post a Comment