]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
util: Allow validation for single XML node
authorTim Wiederhake <twiederh@redhat.com>
Wed, 30 Sep 2020 11:55:02 +0000 (13:55 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Wed, 7 Oct 2020 07:18:07 +0000 (09:18 +0200)
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>
src/util/virxml.c
src/util/virxml.h

index b4d66845603694aef87ecffa82eee0e4deb58cad..8a94de8fe4048e63604a962c84997e0d34889f17 100644 (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)
 {
index 0301f1530873856b29ae1ffde8e31a262bcd6009..fd0d30fcec84cada0d4ce7241a495cff948a0e76 100644 (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);