]> git.ipfire.org Git - thirdparty/snapper.git/commitdiff
Add an XmlFile constructor for loading XML document from a string
authorCheng-Ling Lai <jameslai.tech@gmail.com>
Fri, 10 Jul 2026 09:05:53 +0000 (17:05 +0800)
committerCheng-Ling Lai <jameslai.tech@gmail.com>
Thu, 30 Jul 2026 03:04:18 +0000 (11:04 +0800)
snapper/XmlFile.cc
snapper/XmlFile.h

index 2d95a868cd479c183e2b79cc0411cd96bae49ba3..819f684db0b5fd523fa67c506fa8498c0351c823 100644 (file)
@@ -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);
index 10801b75be04613f2159bb07b31b3b532204565c..38da797eaa6a95689960bec1ad88cb0f012d4472 100644 (file)
@@ -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();