xmlDocSetRootElement removes the node from its previous document tree,
effectively removing the "<cpu>" node from "<domain>" in
virCPUDefParseXML.
Signed-off-by: Tim Wiederhake <twiederh(a)redhat.com>
---
src/conf/cpu_conf.c | 3 +--
src/util/virxml.c | 13 ++++++-------
src/util/virxml.h | 1 -
3 files changed, 7 insertions(+), 10 deletions(-)
diff --git a/src/conf/cpu_conf.c b/src/conf/cpu_conf.c
index c7bea8ae00..58ca1e2019 100644
--- a/src/conf/cpu_conf.c
+++ b/src/conf/cpu_conf.c
@@ -355,8 +355,7 @@ virCPUDefParseXML(xmlXPathContextPtr ctxt,
PKGDATADIR "/schemas")))
return -1;
- if (virXMLValidateNodeAgainstSchema(schemafile, ctxt->doc,
- ctxt->node) < 0)
+ if (virXMLValidateNodeAgainstSchema(schemafile, ctxt->node) < 0)
return -1;
}
diff --git a/src/util/virxml.c b/src/util/virxml.c
index d0d9494009..418be2a898 100644
--- a/src/util/virxml.c
+++ b/src/util/virxml.c
@@ -1551,16 +1551,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 2b40398eee..c0405a39f0 100644
--- a/src/util/virxml.h
+++ b/src/util/virxml.h
@@ -296,7 +296,6 @@ virXMLValidateAgainstSchema(const char *schemafile,
int
virXMLValidateNodeAgainstSchema(const char *schemafile,
- xmlDocPtr doc,
xmlNodePtr node);
void
--
2.26.3