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:
parent
5d325240c6
commit
9faa31ce79
@ -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)
|
||||
{
|
||||
|
@ -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);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user