From: Cheng-Ling Lai Date: Fri, 10 Jul 2026 09:05:53 +0000 (+0800) Subject: Add an XmlFile constructor for loading XML document from a string X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3c287fea061ace53c1fc4982c3347ed2322b104c;p=thirdparty%2Fsnapper.git Add an XmlFile constructor for loading XML document from a string --- diff --git a/snapper/XmlFile.cc b/snapper/XmlFile.cc index 2d95a868..819f684d 100644 --- a/snapper/XmlFile.cc +++ b/snapper/XmlFile.cc @@ -77,6 +77,15 @@ namespace snapper } + XmlFile::XmlFile(FromStringTag, const string& content) + : doc(xmlReadMemory(content.c_str(), content.length(), NULL, NULL, + XML_PARSE_NOBLANKS | XML_PARSE_NONET)) + { + if (!doc) + SN_THROW(IOErrorException("xmlReadMemory failed")); + } + + XmlFile::~XmlFile() { xmlFreeDoc(doc); diff --git a/snapper/XmlFile.h b/snapper/XmlFile.h index 10801b75..38da797e 100644 --- a/snapper/XmlFile.h +++ b/snapper/XmlFile.h @@ -45,9 +45,14 @@ namespace snapper public: + /** Types and values for tag dispatching. */ + struct FromStringTag {}; + static constexpr FromStringTag FromString{}; + XmlFile(); XmlFile(int fd, const string& url); XmlFile(const string& filename); + XmlFile(FromStringTag, const string& content); ~XmlFile();