[libvirt PATCH v3 5/8] util: Allow validation for single XML node

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxx>
---
 src/util/virxml.c | 15 +++++++++++++++
 src/util/virxml.h |  6 ++++++
 2 files changed, 21 insertions(+)

diff --git a/src/util/virxml.c b/src/util/virxml.c
index 5315d4ff6f..2ec526456f 100644
--- a/src/util/virxml.c
+++ b/src/util/virxml.c
@@ -1320,6 +1320,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)
 {
diff --git a/src/util/virxml.h b/src/util/virxml.h
index 0301f15308..fd0d30fcec 100644
--- a/src/util/virxml.h
+++ b/src/util/virxml.h
@@ -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);
 
-- 
2.26.2




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux