1

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();
}
1
  • i would check the documentation of the library. Commented May 11, 2014 at 7:20

1 Answer 1

1

You should check the result of load_file.

Here's what's going on here:

  1. XML tag names can't start with digits. This is defined by XML standard.
  2. pugixml performs this check while loading the document - so load_file() fails, producing an empty document
  3. pugixml does not perform this check while appending nodes or saving document, so it is possible to save an invalid document
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.