diff --git a/ChangeLog b/ChangeLog index 2a5bd9fd..18bbb070 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +Mon Sep 15 11:46:47 CEST 2003 Daniel Veillard + + * parser.c: more parser error factoring + Sun Sep 14 21:53:39 PDT 2003 William Brack * HTMLtree.c: Fixed bug 121394 - missing ns on attributes diff --git a/parser.c b/parser.c index a9b59c4e..1154204a 100644 --- a/parser.c +++ b/parser.c @@ -445,6 +445,33 @@ xmlFatalErrMsgInt(xmlParserCtxtPtr ctxt, xmlParserErrors error, ctxt->disableSAX = 1; } +/** + * xmlFatalErrMsgStr: + * @ctxt: an XML parser context + * @error: the error number + * @msg: the error message + * @val: a string value + * + * Handle a fatal parser error, i.e. violating Well-Formedness constraints + */ +static void +xmlFatalErrMsgStr(xmlParserCtxtPtr ctxt, xmlParserErrors error, + const char *msg, const xmlChar *val) +{ + if (ctxt == NULL) { + xmlGenericError(xmlGenericErrorContext, + "xmlFatalErr: no context !\n"); + return; + } + ctxt->errNo = error; + if ((ctxt->sax == NULL) || (ctxt->sax->error == NULL)) + return; + ctxt->sax->error(ctxt->userData, msg, val); + ctxt->wellFormed = 0; + if (ctxt->recovery == 0) + ctxt->disableSAX = 1; +} + /** * xmlNsErr: * @ctxt: an XML parser context @@ -1564,11 +1591,8 @@ xmlParserHandlePEReference(xmlParserCtxtPtr ctxt) { if ((ctxt->standalone == 1) || ((ctxt->hasExternalSubset == 0) && (ctxt->hasPErefs == 0))) { - if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) - ctxt->sax->error(ctxt->userData, + xmlFatalErrMsgStr(ctxt, XML_ERR_UNDECLARED_ENTITY, "PEReference: %%%s; not found\n", name); - ctxt->wellFormed = 0; - if (ctxt->recovery == 0) ctxt->disableSAX = 1; } else { /* * [ VC: Entity Declared ] @@ -1628,12 +1652,9 @@ xmlParserHandlePEReference(xmlParserCtxtPtr ctxt) { xmlParseTextDecl(ctxt); } } else { - if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) - ctxt->sax->error(ctxt->userData, - "xmlParserHandlePEReference: %s is not a parameter entity\n", - name); - ctxt->wellFormed = 0; - if (ctxt->recovery == 0) ctxt->disableSAX = 1; + xmlFatalErrMsgStr(ctxt, XML_ERR_ENTITY_IS_PARAMETER, + "PEReference: %s is not a parameter entity\n", + name); } } } else { @@ -2474,11 +2495,9 @@ xmlSplitQName(xmlParserCtxtPtr ctxt, const xmlChar *name, xmlChar **prefix) { int first = CUR_SCHAR(cur, l); if (!IS_LETTER(first) && (first != '_')) { - if ((ctxt != NULL) && (ctxt->sax != NULL) && - (ctxt->sax->error != NULL)) - ctxt->sax->error(ctxt->userData, + xmlFatalErrMsgStr(ctxt, XML_NS_ERR_QNAME, "Name %s is not XML Namespace compliant\n", - name); + name); } } cur++; @@ -3678,12 +3697,8 @@ xmlParseComment(xmlParserCtxtPtr ctxt) { } buf[len] = 0; if (!IS_CHAR(cur)) { - ctxt->errNo = XML_ERR_COMMENT_NOT_FINISHED; - if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) - ctxt->sax->error(ctxt->userData, + xmlFatalErrMsgStr(ctxt, XML_ERR_COMMENT_NOT_FINISHED, "Comment not terminated \n