Subject: | Patch adding support of new structured RNG validation function of libxml 2.6.21 |
Hi,
I join a patch to LibXML.xs using xmlRelaxNGSetValidStructuredErrors for RelaxNG validation.
The xmlRelaxNGSetValidStructuredErrors function appears in libxml 2.6.21 and permit to report more convenient error message including filename, line of error and error message.
Cdt,
Laurent Simonneau.
diff -ru XML-LibXML-1.58_1/LibXML.xs XML-LibXML-1.58_1-patched/LibXML.xs
--- XML-LibXML-1.58_1/LibXML.xs 2004-03-25 00:06:14.000000000 +0100
+++ XML-LibXML-1.58_1-patched/LibXML.xs 2005-09-05 10:30:38.518899536 +0200
@@ -112,6 +112,28 @@
SvREFCNT_dec(sv);
}
+/* stores libxml structured errors into $@ */
+void
+LibXML_structurederror_handler(void * ctxt, xmlErrorPtr serror)
+{
+ va_list args;
+ SV * sv;
+ /* xmlParserCtxtPtr context = (xmlParserCtxtPtr) ctxt; */
+ sv = NEWSV(0,512);
+
+ sv_setpvf(sv, "%s %s line %d: %s" , (serror->level == XML_ERR_WARNING) ? "Warning":"Error",
+ serror->file, serror->line, serror->message);
+
+ if (LibXML_error != NULL) {
+ sv_catsv(LibXML_error, sv); /* remember the last error */
+ }
+ else {
+ croak("%s", SvPV_nolen(sv));
+ }
+
+ SvREFCNT_dec(sv);
+}
+
void
LibXML_validity_error(void * ctxt, const char * msg, ...)
{
@@ -6116,10 +6138,9 @@
}
/* Register Error callbacks */
- xmlRelaxNGSetValidErrors( vctxt,
- (xmlRelaxNGValidityErrorFunc)LibXML_error_handler,
- (xmlRelaxNGValidityWarningFunc)LibXML_error_handler,
- vctxt );
+ xmlRelaxNGSetValidStructuredErrors( vctxt,
+ (xmlStructuredErrorFunc)LibXML_structurederror_handler,
+ vctxt );
RETVAL = xmlRelaxNGValidateDoc( vctxt, doc );
xmlRelaxNGFreeValidCtxt( vctxt );