[libvirt PATCH 1/2] virxml: Fix schema validation of individual nodes

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



xmlDocSetRootElement removes the node from its previous document tree,
effectively removing the "<cpu>" node from "<domain>" in virCPUDefParseXML.

Signed-off-by: Tim Wiederhake <twiederh@xxxxxxxxxx>
---
 src/util/virxml.c | 13 ++++++-------
 src/util/virxml.h |  1 -
 2 files changed, 6 insertions(+), 8 deletions(-)

diff --git a/src/util/virxml.c b/src/util/virxml.c
index 117f50f2bf..d816a8e08d 100644
--- a/src/util/virxml.c
+++ b/src/util/virxml.c
@@ -1285,16 +1285,15 @@ virXMLValidateAgainstSchema(const char *schemafile,
 
 
 int
-virXMLValidateNodeAgainstSchema(const char *schemafile,
-                                xmlDocPtr doc,
-                                xmlNodePtr node)
+virXMLValidateNodeAgainstSchema(const char *schemafile, xmlNodePtr node)
 {
-    xmlNodePtr root;
     int ret;
+    xmlDocPtr copy = xmlNewDoc(NULL);
 
-    root = xmlDocSetRootElement(doc, node);
-    ret = virXMLValidateAgainstSchema(schemafile, doc);
-    xmlDocSetRootElement(doc, root);
+    xmlDocSetRootElement(copy, xmlCopyNode(node, true));
+    ret = virXMLValidateAgainstSchema(schemafile, copy);
+
+    xmlFreeDoc(copy);
     return ret;
 }
 
diff --git a/src/util/virxml.h b/src/util/virxml.h
index de171dce12..8a8ec2a6df 100644
--- a/src/util/virxml.h
+++ b/src/util/virxml.h
@@ -213,7 +213,6 @@ virXMLValidateAgainstSchema(const char *schemafile,
 
 int
 virXMLValidateNodeAgainstSchema(const char *schemafile,
-                                xmlDocPtr doc,
                                 xmlNodePtr node);
 
 void
-- 
2.26.2




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux