After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 126793 - structured error from xmlXPathCompile lacks some info
structured error from xmlXPathCompile lacks some info
Status: VERIFIED FIXED
Product: libxml2
Classification: Platform
Component: general
2.6.1
Other Linux
: Normal minor
: ---
Assigned To: Daniel Veillard
libxml QA maintainers
Depends on:
Blocks:
 
 
Reported: 2003-11-12 09:59 UTC by pajas
Modified: 2009-08-15 18:40 UTC
See Also:
GNOME target: ---
GNOME version: ---



Description pajas 2003-11-12 09:59:50 UTC
If xmlXPathCompile(comp) fails, it doesn't provide exact position of
compilation failure to a structured handler (via int1 and str1). On the
other hand, xmlXPathEvalExpr() or xmlXPathEval() work fine.
Below is a dump of xmlError structures I get:

xmlXPathEvalExpr() or xmlXPathEval() (OK):
domain: 12
code: 1207
message: Invalid expression\n
level: ERROR
file:
line: 0
str1: foo::bar
str2:
str3:
int1: 4
int2: 0
ctxt: 0
node: 0

xmlXPathCompile (BAD):

domain: 12
code: 1207
message: Invalid expression\n
level: ERROR
file:
line: 0
str1:
str2:
str3:
int1: 0
int2: 0
ctxt: 0
node: 0
Comment 1 pajas 2003-11-18 14:45:53 UTC
Similarly:

parser reports no structured errors at all via a registered structured
error handler (this problem affects both XML parsing errors or
validation errors). 

Well-formedness errors can be taken from parser ctxt->lastError at the
end of parsing but validation errors can't (ctxt->lastError is ERR_OK,
only ctxt->valid == 0 indicates a validity error).

Non-structured errors are repotred in both cases. 

Here is a simple C code to test with (if given an argument, parses
that file, otherwise parses the inline XML document).

__BEGIN_TEST_CASE___
#include <stdarg.h>
#include <unistd.h>
#include <libxml/parser.h>
#include <libxml/parserInternals.h>
#include <libxml/xmlerror.h>
#include <libxml/tree.h>

char* xmldoc = 
"<?xml version='1.0'?>"
"<!DOCTYPE boo []>"
"<foo/>";

void
my_flat_err(void *ctx, const char *msg, ...) {
    printf("<Flat-error-invoked>\n");
    va_list ap;
    va_start(ap, msg);
    vfprintf(stderr, msg, ap);
    va_end(ap);
    printf("</Flat-error-invoked>\n");
}

void
my_struct_err(void *userData, xmlErrorPtr err) {
    printf("<structured-error-invoked/>\n");
}


int
main (int argn, char** argv) {
    int ret;
    xmlParserCtxtPtr ctxt;
    xmlDocPtr doc;
    xmlSetGenericErrorFunc( NULL , (xmlGenericErrorFunc) my_flat_err);    
    xmlSetStructuredErrorFunc( NULL ,
(xmlStructuredErrorFunc)my_struct_err);

    if (argn<=1) {
        ctxt = xmlCreateMemoryParserCtxt((const char*)xmldoc,
strlen(xmldoc));
        if ( ctxt->input != NULL ) {
            ctxt->input->filename = xmlStrdup((const xmlChar *) "");
        }
        xmlCtxtUseOptions(ctxt, XML_PARSE_DTDVALID);
        ret = xmlParseDocument(ctxt);
    } else {
        ctxt = xmlNewParserCtxt();
        doc = xmlCtxtReadFile(ctxt, argv[1], NULL, XML_PARSE_DTDVALID);
    }
    if (ctxt->valid == 0)
        printf("novalid\n");
    doc = ctxt->myDoc;
    xmlFreeParserCtxt(ctxt);
    /*    doc = xmlReadMemory(xmldoc, strlen(xmldoc), NULL, NULL,
XML_PARSE_DTDVALID); */
    if (doc)
        xmlFree(doc);
}
Comment 2 pajas 2003-11-18 14:51:27 UTC
Oh, also forgot to mentioned:

Daniel, the non-structured error handler is still called several times
per error as with old libxml2 versions, while you once told me on the
list that libxml2.6.x's behaviour was to call the handler only once
per an error (at least that's how I understood it).

Thanks, Petr
Comment 3 Daniel Veillard 2003-12-08 10:29:27 UTC
Okay, I have tried to fix the structured error handling problems
you raised . It should be fixed in CVS now:

paphio:~/XML -> gcc -o tst -Iinclude tst.c .libs/libxml2.a -lm -lz
-lpthread
paphio:~/XML -> ./tst
<structured-error-invoked/>
novalid
paphio:~/XML ->

  including the XPath reporting glitches (but untested). See also
bug #126211 which is related.
  For the non-structured error handler there is still multiple
callbacks but the number is bounded per error, it used in some case
to be called once per character printed in the context, that I
tried to fix. If the issue is really critical, I could try to
fix this, but I would rather get the structured handler ready
instead.

Daniel
Comment 4 Daniel Veillard 2004-01-26 13:25:06 UTC
This should be closed in release of libxml2-2.6.5,
                                                                     
          
Daniel