The following bit of code fails
xmlInitParser();
xmlDocPtr maindoc = xmlReadFile("maindoc.xml", NULL, 0);
xmlDocPtr subdoc = xmlReadFile("subdoc.xml", NULL, 0);
xmlNodePtr content = xmlDocGetRootElement(subdoc);
xmlUnlinkNode(content);
xmlAddChild(xmlDocGetRootElement(maindoc), content);
xmlFreeDoc(subdoc);
xmlFreeDoc(maindoc);
xmlCleanupParser();
with a crash upon calling xmlFreeDoc(maindoc) (problem freeing memory)
where this code succeeds just fine and dandy
xmlInitParser();
xmlDocPtr maindoc = xmlParseFile("maindoc.xml");
xmlDocPtr subdoc = xmlParseFile("subdoc.xml");
xmlNodePtr content = xmlDocGetRootElement(subdoc);
xmlUnlinkNode(content);
xmlAddChild(xmlDocGetRootElement(maindoc), content);
xmlFreeDoc(subdoc);
xmlFreeDoc(maindoc);
xmlCleanupParser();
I understand I should use xmlReadFile instead of xmlParseFile. However, I
can't figure on what's different between the two that could be causing the
crash in the first block of code?
Note, I've tried with multiple versions, even 2.9.2.
Alternatively, how *should* I be structuring the code to do what I'm doing
here? (I know a call to
xmlAddChild(xmlDocGetRootElement(maindoc),
xmlCopyNode(xmlDocGetRootElement(subdoc), 1));
in place of the get/unlink/add sequence works but I'd like to understand
why the code above fails.)
- Paul Braman
_______________________________________________
xml mailing list, project page http://xmlsoft.org/
[email protected]
https://mail.gnome.org/mailman/listinfo/xml