提交 4702687c 编写于 作者: J Ján Tomko

Introduce virXMLValidatorValidate

Split out the code for XML validation into a new function.
上级 87ae612d
......@@ -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);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册