virxml: Fix schema validation of individual nodes

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

Signed-off-by: Tim Wiederhake <twiederh@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
Tim Wiederhake 2021-04-20 13:27:49 +02:00 committed by Michal Privoznik
parent 6e91cbfdad
commit baaf79ac0e
3 changed files with 7 additions and 10 deletions

View File

@ -355,8 +355,7 @@ virCPUDefParseXML(xmlXPathContextPtr ctxt,
PKGDATADIR "/schemas"))) PKGDATADIR "/schemas")))
return -1; return -1;
if (virXMLValidateNodeAgainstSchema(schemafile, ctxt->doc, if (virXMLValidateNodeAgainstSchema(schemafile, ctxt->node) < 0)
ctxt->node) < 0)
return -1; return -1;
} }

View File

@ -1551,16 +1551,15 @@ virXMLValidateAgainstSchema(const char *schemafile,
int int
virXMLValidateNodeAgainstSchema(const char *schemafile, virXMLValidateNodeAgainstSchema(const char *schemafile, xmlNodePtr node)
xmlDocPtr doc,
xmlNodePtr node)
{ {
xmlNodePtr root;
int ret; int ret;
xmlDocPtr copy = xmlNewDoc(NULL);
root = xmlDocSetRootElement(doc, node); xmlDocSetRootElement(copy, xmlCopyNode(node, true));
ret = virXMLValidateAgainstSchema(schemafile, doc); ret = virXMLValidateAgainstSchema(schemafile, copy);
xmlDocSetRootElement(doc, root);
xmlFreeDoc(copy);
return ret; return ret;
} }

View File

@ -296,7 +296,6 @@ virXMLValidateAgainstSchema(const char *schemafile,
int int
virXMLValidateNodeAgainstSchema(const char *schemafile, virXMLValidateNodeAgainstSchema(const char *schemafile,
xmlDocPtr doc,
xmlNodePtr node); xmlNodePtr node);
void void