Reputation: 28807
How do I get a complete copy of a RapidXML xml_document?
There is a clone_node function; how to use to to create a complete copy of an existing document?
Upvotes: 2
Views: 1876
Reputation: 3119
as you already guessed there is the function clone_node
method. From the online help:
xml_node* clone_node(const xml_node< Ch > *source, xml_node< Ch > *result=0);
Clones an xml_node and its hierarchy of child nodes and attributes. Nodes and attributes are allocated from this memory pool. Names and values are not cloned, they are shared between the clone and the source. Result node can be optionally specified as a second parameter, in which case its contents will be replaced with cloned source node. This is useful when you want to clone entire document.
The approach proposed by FreshCode is quite simple, but adds an unnecessary overhead to "toString & parseBack" that you may want to avoid.
Upvotes: 4
Reputation: 28807
I'm sure there's a cleaner, tree-based approach, but I solved it with the following, where str is the xml output from another doc:
xml_document<> doc;
doc.parse<0>(doc.allocate_string(str));
Upvotes: 1