Allow to construct a XML tree from a text buffer

This commit is contained in:
Robin Gareus 2016-10-29 17:03:34 +02:00
parent 5ed764178a
commit 06700cb2f4
2 changed files with 10 additions and 3 deletions

View file

@ -70,7 +70,7 @@ public:
bool read(const std::string& fn) { set_filename(fn); return read_internal(false); }
bool read_and_validate() { return read_internal(true); }
bool read_and_validate(const std::string& fn) { set_filename(fn); return read_internal(true); }
bool read_buffer(const std::string&);
bool read_buffer(const std::string&, bool to_tree_doc = false);
bool write() const;
bool write(const std::string& fn) { set_filename(fn); return write(); }

View file

@ -120,7 +120,7 @@ XMLTree::read_internal(bool validate)
}
bool
XMLTree::read_buffer(const string& buffer)
XMLTree::read_buffer(const string& buffer, bool to_tree_doc)
{
xmlDocPtr doc;
@ -135,7 +135,14 @@ XMLTree::read_buffer(const string& buffer)
}
_root = readnode(xmlDocGetRootElement(doc));
xmlFreeDoc(doc);
if (to_tree_doc) {
if (_doc) {
xmlFreeDoc (_doc);
}
_doc = doc;
} else {
xmlFreeDoc (doc);
}
return true;
}