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

util: Allow validation for single XML node

Validation is usually performed on an entire document. If we are only
interested in validating a single nested node that can occur in
different contexts, this would require writing different schemas for
any of those different contexts.

By temporarily replacing the document's root node, we can validate the
relevant node only.

Signed-off-by: Tim Wiederhake <twiederh@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
This commit is contained in:
Tim Wiederhake 2020-09-30 13:55:02 +02:00 committed by Peter Krempa
parent 5d325240c6
commit 9faa31ce79
2 changed files with 21 additions and 0 deletions

View File

@ -1315,6 +1315,21 @@ virXMLValidateAgainstSchema(const char *schemafile,
}
int
virXMLValidateNodeAgainstSchema(const char *schemafile,
xmlDocPtr doc,
xmlNodePtr node)
{
xmlNodePtr root;
int ret;
root = xmlDocSetRootElement(doc, node);
ret = virXMLValidateAgainstSchema(schemafile, doc);
xmlDocSetRootElement(doc, root);
return ret;
}
void
virXMLValidatorFree(virXMLValidatorPtr validator)
{

View File

@ -212,6 +212,12 @@ virXMLValidatorValidate(virXMLValidatorPtr validator,
int
virXMLValidateAgainstSchema(const char *schemafile,
xmlDocPtr xml);
int
virXMLValidateNodeAgainstSchema(const char *schemafile,
xmlDocPtr doc,
xmlNodePtr node);
void
virXMLValidatorFree(virXMLValidatorPtr validator);