Introduce virXMLValidatorValidate

Split out the code for XML validation into a new function.
This commit is contained in:
Ján Tomko 2016-06-07 18:58:02 +02:00
parent 87ae612de9
commit 4702687cfb
3 changed files with 26 additions and 6 deletions

View File

@ -2567,6 +2567,7 @@ virXMLSaveFile;
virXMLValidateAgainstSchema;
virXMLValidatorFree;
virXMLValidatorInit;
virXMLValidatorValidate;
virXPathBoolean;
virXPathInt;
virXPathLong;

View File

@ -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;

View File

@ -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);