applied patch from Steve Ball to provide structured error reports.
* xmlreader.c, include/libxml/xmlreader.h: applied patch from
Steve Ball to provide structured error reports.
diff --git a/ChangeLog b/ChangeLog
index f3d4ccd..ef50808 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+Mon Feb 2 16:13:33 PST 2004 William Brack <wbrack@mmm.com.hk>
+
+ * xmlreader.c, include/libxml/xmlreader.h: applied patch from
+ Steve Ball to provide structured error reports.
+
Sun Feb 1 01:48:14 PST 2004 William Brack <wbrack@mmm.com.hk>
* tree.c, include/libxml/tree.h: moved serialization of
diff --git a/include/libxml/xmlreader.h b/include/libxml/xmlreader.h
index f4add56..76499b8 100644
--- a/include/libxml/xmlreader.h
+++ b/include/libxml/xmlreader.h
@@ -304,6 +304,10 @@
xmlTextReaderSetErrorHandler(xmlTextReaderPtr reader,
xmlTextReaderErrorFunc f,
void *arg);
+XMLPUBFUN void XMLCALL
+ xmlTextReaderSetStructuredErrorHandler(xmlTextReaderPtr reader,
+ xmlStructuredErrorFunc f,
+ void *arg);
XMLPUBFUN void XMLCALL
xmlTextReaderGetErrorHandler(xmlTextReaderPtr reader,
xmlTextReaderErrorFunc *f,
diff --git a/xmlreader.c b/xmlreader.c
index 749cb31..a7e1bf3 100644
--- a/xmlreader.c
+++ b/xmlreader.c
@@ -157,6 +157,8 @@
#endif
int preserves; /* level of preserves */
int parserFlags; /* the set of options set */
+ /* Structured error handling */
+ xmlStructuredErrorFunc sErrorFunc; /* callback function */
};
#define NODE_IS_EMPTY 0x1
@@ -3891,6 +3893,17 @@
}
static void
+xmlTextReaderStructuredError(void *ctxt, xmlErrorPtr error) {
+ xmlParserCtxtPtr ctx = (xmlParserCtxtPtr) ctxt;
+ xmlTextReaderPtr reader = (xmlTextReaderPtr) ctx->_private;
+
+ if (error && reader->sErrorFunc) {
+ reader->sErrorFunc(reader->errorFuncArg,
+ (xmlErrorPtr) error);
+ }
+}
+
+static void
xmlTextReaderError(void *ctxt, const char *msg, ...) {
va_list ap;
@@ -3965,6 +3978,7 @@
void *arg) {
if (f != NULL) {
reader->ctxt->sax->error = xmlTextReaderError;
+ reader->ctxt->sax->serror = NULL;
reader->ctxt->vctxt.error = xmlTextReaderValidityError;
reader->ctxt->sax->warning = xmlTextReaderWarning;
reader->ctxt->vctxt.warning = xmlTextReaderValidityWarning;
@@ -3978,11 +3992,48 @@
reader->ctxt->sax->warning = xmlParserWarning;
reader->ctxt->vctxt.warning = xmlParserValidityWarning;
reader->errorFunc = NULL;
+ reader->sErrorFunc = NULL;
reader->errorFuncArg = NULL;
}
}
/**
+* xmlTextReaderSetStructuredErrorHandler:
+ * @reader: the xmlTextReaderPtr used
+ * @f: the callback function to call on error and warnings
+ * @arg: a user argument to pass to the callback function
+ *
+ * Register a callback function that will be called on error and warnings.
+ *
+ * If @f is NULL, the default error and warning handlers are restored.
+ */
+void
+xmlTextReaderSetStructuredErrorHandler(xmlTextReaderPtr reader,
+ xmlStructuredErrorFunc f,
+ void *arg) {
+ if (f != NULL) {
+ reader->ctxt->sax->serror = xmlTextReaderStructuredError;
+ reader->ctxt->vctxt.error = xmlTextReaderValidityError;
+ reader->ctxt->sax->warning = xmlTextReaderWarning;
+ reader->ctxt->vctxt.warning = xmlTextReaderValidityWarning;
+ reader->sErrorFunc = f;
+ reader->errorFunc = NULL;
+ reader->errorFuncArg = arg;
+ }
+ else {
+ /* restore defaults */
+ reader->ctxt->sax->error = xmlParserError;
+ reader->ctxt->sax->serror = NULL;
+ reader->ctxt->vctxt.error = xmlParserValidityError;
+ reader->ctxt->sax->warning = xmlParserWarning;
+ reader->ctxt->vctxt.warning = xmlParserValidityWarning;
+ reader->errorFunc = NULL;
+ reader->sErrorFunc = NULL;
+ reader->errorFuncArg = NULL;
+ }
+}
+
+/**
* xmlTextReaderIsValid:
* @reader: the xmlTextReaderPtr used
*