[xml] "xmlReadxxx & structured error handler & userData"



Hi,

if using the xmlReadxxx functions with a registered structured error 
handler, libxml2 channels a "xmlParserCtxtPtr" as the userData to the 
error handler. This is due to "xmlInitParserCtxt" where ctxt->userData 
is set to the ctxt itself, and the fact that the user cannot set 
ctxt->userData explicitely here. I wonder if one could add an 
initialization of "ctxt->userData = xmlStructuredError" after the 
context has been created to the xmlReadxxx functions.

Two examples:


1. Using a non-existing filename with xmlReadFile.

--- function "__xmlLoaderErr":
     channel = _xmlParserWarning
     schannel = ctxt->sax->serror (= NULL)
     data = ctxt->userData
--> function "__xmlRaiseError":
     if (schannel == NULL)
         schannel = xmlStructuredError;

Semantically this leads to the following call:
--> schannel( <ctxt->userData>, <xmlStructuredError>);


2. Using a document with a malformed prolog ("<<?xml version="1.0" 
encoding="ISO-8859-1" ?>")

--- function "xmlParseStartTag2"
--> function "xmlFatalErrMsg"
--> function "__xmlRaiseError":
     if (schannel == NULL)
         schannel = xmlStructuredError;
     data = ctxt->userData;

Semantically this leads to the following call:
--> schannel( <ctxt->userData>, <xmlStructuredError>);


Any other clues how to obtain the xmlGenericErrorContext, that was set 
with "xmlSetStructuredErrorFunc" if using xmlReadxxx functions?


Regards,

Kasimier




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]