1
0
mirror of https://gitlab.com/libvirt/libvirt.git synced 2024-12-27 07:22:07 +03:00

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")))
return -1;
if (virXMLValidateNodeAgainstSchema(schemafile, ctxt->doc,
ctxt->node) < 0)
if (virXMLValidateNodeAgainstSchema(schemafile, ctxt->node) < 0)
return -1;
}

View File

@ -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;
}

View File

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