In this simple code after invoking second(), 1.xml has only one node "1". Why pugi replaces node and what should I do for correct modifying?
void first()
{
pugi::xml_document document;
pugi::xml_parse_result result = document.load_file("C:\\1.xml", parse_full);
pugi::xml_node node = document.append_child("0");
node.append_attribute("message") = "something";
document.save_file("C:\\1.xml");
}
void second()
{
pugi::xml_document document;
pugi::xml_parse_result result = document.load_file("C:\\1.xml", parse_full);
pugi::xml_node node = document.append_child("1");
node.append_attribute("message") = "something else";
document.save_file("C:\\1.xml");
}
void test()
{
first();
second();
}
You should check the result of load_file
.
Here's what's going on here:
load_file()
fails, producing an empty document