1
0
mirror of https://gitlab.gnome.org/GNOME/libxml2.git synced 2025-07-29 11:41:22 +03:00

working on better error reporting of validity errors, especially providing

* error.c valid.c: working on better error reporting of validity
  errors, especially providing an accurate context.
* result/valid/xlink.xml.err result/valid/rss.xml.err: better
  error reports in those cases.
Daniel
This commit is contained in:
Daniel Veillard
2002-09-05 14:21:15 +00:00
parent 3487c8d9bb
commit 76575769f3
5 changed files with 51 additions and 22 deletions

View File

@ -1,3 +1,10 @@
Thu Sep 5 16:19:18 CEST 2002 Daniel Veillard <daniel@veillard.com>
* error.c valid.c: working on better error reporting of validity
errors, especially providing an accurate context.
* result/valid/xlink.xml.err result/valid/rss.xml.err: better
error reports in those cases.
Thu Sep 5 13:29:47 CEST 2002 Daniel Veillard <daniel@veillard.com> Thu Sep 5 13:29:47 CEST 2002 Daniel Veillard <daniel@veillard.com>
* DOCBparser.c HTMLparser.c c14n.c entities.c list.c * DOCBparser.c HTMLparser.c c14n.c entities.c list.c

31
error.c
View File

@ -350,22 +350,34 @@ xmlParserValidityError(void *ctx, const char *msg, ...)
xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
xmlParserInputPtr input = NULL; xmlParserInputPtr input = NULL;
char * str; char * str;
int len = xmlStrlen((const xmlChar *) msg);
static int had_info = 0;
int need_context = 0;
int need_info = 0;
if (ctxt != NULL) { if ((len > 1) && (msg[len - 2] != ':')) {
input = ctxt->input; if (ctxt != NULL) {
if ((input->filename == NULL) && (ctxt->inputNr > 1)) input = ctxt->input;
input = ctxt->inputTab[ctxt->inputNr - 2]; if ((input->filename == NULL) && (ctxt->inputNr > 1))
input = ctxt->inputTab[ctxt->inputNr - 2];
xmlParserPrintFileInfo(input);
if (had_info == 0) {
xmlParserPrintFileInfo(input);
}
}
xmlGenericError(xmlGenericErrorContext, "validity error: ");
need_context = 1;
had_info = 0;
} else {
had_info = 1;
} }
xmlGenericError(xmlGenericErrorContext, "validity error: ");
XML_GET_VAR_STR(msg, str); XML_GET_VAR_STR(msg, str);
xmlGenericError(xmlGenericErrorContext, "%s", str); xmlGenericError(xmlGenericErrorContext, "%s", str);
if (str != NULL) if (str != NULL)
xmlFree(str); xmlFree(str);
if (ctxt != NULL) { if ((ctxt != NULL) && (input != NULL)) {
xmlParserPrintFileContext(input); xmlParserPrintFileContext(input);
} }
} }
@ -385,8 +397,9 @@ xmlParserValidityWarning(void *ctx, const char *msg, ...)
xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
xmlParserInputPtr input = NULL; xmlParserInputPtr input = NULL;
char * str; char * str;
int len = xmlStrlen((const xmlChar *) msg);
if (ctxt != NULL) { if ((ctxt != NULL) && (len != 0) && (msg[len - 1] != ':')) {
input = ctxt->input; input = ctxt->input;
if ((input->filename == NULL) && (ctxt->inputNr > 1)) if ((input->filename == NULL) && (ctxt->inputNr > 1))
input = ctxt->inputTab[ctxt->inputNr - 2]; input = ctxt->inputTab[ctxt->inputNr - 2];

View File

@ -1,3 +1,3 @@
./test/valid/rss.xml:177: validity error: Element rss does not carry attribute version ./test/valid/rss.xml:172: validity error: Element rss does not carry attribute version
</rss> </rss>
^ ^

View File

@ -1,6 +1,6 @@
./test/valid/xlink.xml:450: validity error: ID dt-arc already defined ./test/valid/xlink.xml:450: validity error: ID dt-arc already defined
<p><termdef id="dt-arc" term="Arc">An <term>arc</term> is contained within an <p><termdef id="dt-arc" term="Arc">An <term>arc</term> is contained within an
^ ^
./test/valid/xlink.xml:530: validity error: IDREF attribute def references an unknown ID "dt-xlg" ./test/valid/xlink.xml:199: validity error: IDREF attribute def references an unknown ID "dt-xlg"
^ ^

31
valid.c
View File

@ -311,23 +311,27 @@ xmlValidStateDebug(xmlValidCtxtPtr ctxt) {
#define VECTXT(ctxt, node) \ #define VECTXT(ctxt, node) \
if ((ctxt != NULL) && (ctxt->error != NULL) && \ if ((ctxt != NULL) && (ctxt->error != NULL) && \
(node != NULL) && (node->type == XML_ELEMENT_NODE)) { \ (node != NULL)) { \
if ((node->doc != NULL) && (node->doc->URL != NULL)) \ xmlChar *base = xmlNodeGetBase(NULL,node); \
ctxt->error(ctxt->userData, "%s:%d:", node->doc->URL,\ if (base != NULL) { \
ctxt->error(ctxt->userData, "%s:%d: ", base, \
(int) node->content); \ (int) node->content); \
else \ xmlFree(base); \
ctxt->error(ctxt->userData, ":%d:", \ } else \
ctxt->error(ctxt->userData, ":%d: ", \
(int) node->content); \ (int) node->content); \
} }
#define VWCTXT(ctxt, node) \ #define VWCTXT(ctxt, node) \
if ((ctxt != NULL) && (ctxt->warning != NULL) && \ if ((ctxt != NULL) && (ctxt->warning != NULL) && \
(node != NULL) && (node->type == XML_ELEMENT_NODE)) { \ (node != NULL)) { \
if ((node->doc != NULL) && (node->doc->URL != NULL)) \ xmlChar *base = xmlNodeGetBase(NULL,node); \
ctxt->warning(ctxt->userData, "%s:%d:", node->doc->URL,\ if (base != NULL) { \
ctxt->warning(ctxt->userData, "%s:%d: ", base, \
(int) node->content); \ (int) node->content); \
else \ xmlFree(base); \
ctxt->warning(ctxt->userData, ":%d:", \ } else \
ctxt->warning(ctxt->userData, ":%d: ", \
(int) node->content); \ (int) node->content); \
} }
@ -1904,8 +1908,10 @@ xmlAddID(xmlValidCtxtPtr ctxt, xmlDocPtr doc, const xmlChar *value,
/* /*
* The id is already defined in this DTD. * The id is already defined in this DTD.
*/ */
if (ctxt != NULL) if (ctxt != NULL) {
VECTXT(ctxt, attr->parent);
VERROR(ctxt->userData, "ID %s already defined\n", value); VERROR(ctxt->userData, "ID %s already defined\n", value);
}
xmlFreeID(ret); xmlFreeID(ret);
return(NULL); return(NULL);
} }
@ -4786,6 +4792,7 @@ xmlValidateRoot(xmlValidCtxtPtr ctxt, xmlDocPtr doc) {
if ((xmlStrEqual(doc->intSubset->name, BAD_CAST "HTML")) && if ((xmlStrEqual(doc->intSubset->name, BAD_CAST "HTML")) &&
(xmlStrEqual(root->name, BAD_CAST "html"))) (xmlStrEqual(root->name, BAD_CAST "html")))
goto name_ok; goto name_ok;
VECTXT(ctxt, root);
VERROR(ctxt->userData, VERROR(ctxt->userData,
"Not valid: root and DTD name do not match '%s' and '%s'\n", "Not valid: root and DTD name do not match '%s' and '%s'\n",
root->name, doc->intSubset->name); root->name, doc->intSubset->name);
@ -4874,6 +4881,7 @@ xmlValidateRef(xmlRefPtr ref, xmlValidCtxtPtr ctxt,
if (attr->atype == XML_ATTRIBUTE_IDREF) { if (attr->atype == XML_ATTRIBUTE_IDREF) {
id = xmlGetID(ctxt->doc, name); id = xmlGetID(ctxt->doc, name);
if (id == NULL) { if (id == NULL) {
VECTXT(ctxt, attr->parent);
VERROR(ctxt->userData, VERROR(ctxt->userData,
"IDREF attribute %s references an unknown ID \"%s\"\n", "IDREF attribute %s references an unknown ID \"%s\"\n",
attr->name, name); attr->name, name);
@ -4895,6 +4903,7 @@ xmlValidateRef(xmlRefPtr ref, xmlValidCtxtPtr ctxt,
*cur = 0; *cur = 0;
id = xmlGetID(ctxt->doc, str); id = xmlGetID(ctxt->doc, str);
if (id == NULL) { if (id == NULL) {
VECTXT(ctxt, attr->parent);
VERROR(ctxt->userData, VERROR(ctxt->userData,
"IDREFS attribute %s references an unknown ID \"%s\"\n", "IDREFS attribute %s references an unknown ID \"%s\"\n",
attr->name, str); attr->name, str);