Change a node to be a comment node

437 Views Asked by At

I have a reference to an xml_node. Is there a way to change it to be a comment type node (node_comment)? Essentially to comment the node out.

1

There are 1 best solutions below

0
On

For converting an element into a comment, you'd want to use something along these lines:

std::ostringstream oss;
node.print(oss, "", pugi::format_raw);

auto comment = node.parent().insert_child_before(pugi::node_comment, node);
comment.set_value(oss.str().c_str());

node.parent().remove_child(node);