mirror of https://gitee.com/openkylin/libvirt.git
Introduce virXMLValidatorValidate
Split out the code for XML validation into a new function.
This commit is contained in:
parent
87ae612de9
commit
4702687cfb
|
@ -2567,6 +2567,7 @@ virXMLSaveFile;
|
|||
virXMLValidateAgainstSchema;
|
||||
virXMLValidatorFree;
|
||||
virXMLValidatorInit;
|
||||
virXMLValidatorValidate;
|
||||
virXPathBoolean;
|
||||
virXPathInt;
|
||||
virXPathLong;
|
||||
|
|
|
@ -1156,15 +1156,11 @@ virXMLValidatorInit(const char *schemafile)
|
|||
|
||||
|
||||
int
|
||||
virXMLValidateAgainstSchema(const char *schemafile,
|
||||
xmlDocPtr doc)
|
||||
virXMLValidatorValidate(virXMLValidatorPtr validator,
|
||||
xmlDocPtr doc)
|
||||
{
|
||||
virXMLValidatorPtr validator = NULL;
|
||||
int ret = -1;
|
||||
|
||||
if (!(validator = virXMLValidatorInit(schemafile)))
|
||||
return -1;
|
||||
|
||||
if (xmlRelaxNGValidateDoc(validator->rngValid, doc) != 0) {
|
||||
virReportError(VIR_ERR_XML_INVALID_SCHEMA,
|
||||
_("Unable to validate doc against %s\n%s"),
|
||||
|
@ -1174,7 +1170,26 @@ virXMLValidateAgainstSchema(const char *schemafile,
|
|||
}
|
||||
|
||||
ret = 0;
|
||||
cleanup:
|
||||
virBufferFreeAndReset(&validator->buf);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
virXMLValidateAgainstSchema(const char *schemafile,
|
||||
xmlDocPtr doc)
|
||||
{
|
||||
virXMLValidatorPtr validator = NULL;
|
||||
int ret = -1;
|
||||
|
||||
if (!(validator = virXMLValidatorInit(schemafile)))
|
||||
return -1;
|
||||
|
||||
if (virXMLValidatorValidate(validator, doc) < 0)
|
||||
goto cleanup;
|
||||
|
||||
ret = 0;
|
||||
cleanup:
|
||||
virXMLValidatorFree(validator);
|
||||
return ret;
|
||||
|
|
|
@ -192,6 +192,10 @@ typedef virXMLValidator *virXMLValidatorPtr;
|
|||
virXMLValidatorPtr
|
||||
virXMLValidatorInit(const char *schemafile);
|
||||
|
||||
int
|
||||
virXMLValidatorValidate(virXMLValidatorPtr validator,
|
||||
xmlDocPtr doc);
|
||||
|
||||
int
|
||||
virXMLValidateAgainstSchema(const char *schemafile,
|
||||
xmlDocPtr xml);
|
||||
|
|
Loading…
Reference in New Issue