falcong / pugixml

Automatically exported from code.google.com/p/pugixml
0 stars 0 forks source link

how to save subtree to a xml file #149

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
I have a xml file named "test.xml" as below:
<foo bar="baz"><call>hey</call></foo>

At first I use load_file to open it, then I change the contents like:
<foo bar="hello"><call>hey</call></foo>

But I don't want to save it, so I change it like:
<foo bar="hello"><call>world</call></foo>

Then I use save_file to save the whole file, but i just want to save it like 
this:
<foo bar="baz"><call>world</call></foo>

How can I deal with it?

Thanks!!!

Original issue reported on code.google.com by diablos...@yahoo.com.cn on 24 Feb 2012 at 6:05

GoogleCodeExporter commented 9 years ago
Please, clarify the question...

From your description it seems that you changed the attribute value and the 
PCDATA value, but you want to save the tree without attribute changes?..

It is possible to save a subtree to file like this:

#include <fstream>

std::ofstream out("filename");
doc.child("foo").child("call").print(out);

Original comment by arseny.k...@gmail.com on 27 Feb 2012 at 4:29

GoogleCodeExporter commented 9 years ago
Closing because of lack of activity; if you need further help on this issue, 
just leave a comment that says so.

Original comment by arseny.k...@gmail.com on 14 Mar 2012 at 3:21