On Mon, Aug 13, 2012 at 09:43:25PM -0400, John Schember wrote: > I'm having trouble getting custom error functions working properly. I > want to be able to get the error information from parsing errors so I > can store it for use later. Specifically with Relax-NG > I would like to know this also. In fact, I already inquired about it on this list.
John > I've attached a sample application which demonstrates how I'm setting > up error handlers. I'm using 2.8.0 on OS X 10.8.0. I'm compiling and > running with: > > $ gcc -I /usr/local/Cellar/libxml2/2.8.0/include/libxml2/ -lxml2 test.c > $ /a.out 1 b.xml c.xml schema.xml > $ /a.out 2 b.xml c.xml schema.xml > $ /a.out 3 b.xml c.xml schema.xml > $ /a.out 4 b.xml c.xml schema.xml > $ /a.out 5 b.xml c.xml schema.xml > > The numbers on the command line represent different functions I'm > setting for the error handler and different types of errors generated > by the parser. > > 1: error function is fprintf and a validation error occurs > 2: error function is err_func (a varg function that passes input to > fprintf) and a validation error occurs. > 3. error function is fprintf and a structural error occurs. > 4. error function is err_func and a structural error occurs. > > I'm seeing strange output when comparing the various tests. > > A) Test 1 gives, "b.xml:5: element note: Relax-NG validity error : Did > not expect element note there" as the output but test 2 gives, "Did > not expect element note there". Test 2 just passes the vargs on to > fprintf which test 1 is calling directly. Yet as far as I can tell the > varg list that err_func receives "%s" as the message and the last part > of the error message as the output. So, why is fprintf getting extra > error text? > > B) Test 3 and Test 4 gives the same output and my marker for err_func > is never displayed. Test 4 thus isn't every calling err_func but must > be using the internal error handler. I've tried multiple ways to set > structural error handlers (comments in test.c) but none seem to work. > There are 5 different error handler setting functions in test.c I'm > not sure which if any of the 5 are correct. > > xmlRelaxNGSetParserErrors and xmlRelaxNGSetParserStructuredErrors > don't appear to do anything. > > Setting xmlRelaxNGSetValidStructuredErrors causes no error messages to > be relayed to the error handling functions. fprintf (as far as I can > tell) and err_func (marker is displayed) do not have any message text > and display not error output. > > xmlSetGenericErrorFunc and xmlSetStructuredErrorFunc both end up with > strange output when they are set. When 5 is used for the test number > (5 runs all 4 tests in a row) fprintf test 3 calls err_func multiple > times. It's the full error message just each part is sent to err_func > separately. That in itself is strange but what is more strange is > error fprintf is the error handler for that test. However, this could > be due to some kind of misuse due to the test function calling this on > each test. But I don't see how redefining a general error function > would cause error handling to use a function other than what was > defined... > > How do I properly define an error handler for both validation and > malformed xml errors? How do I get the full error message from the > error function? Basically, I'm confused and I'm hoping someone can > point me in the right direction as to what I'm missing. > > John Schember > _______________________________________________ > xml mailing list, project page http://xmlsoft.org/ > [email protected] > https://mail.gnome.org/mailman/listinfo/xml -- John J. Boyer; President, Chief Software Developer Abilitiessoft, Inc. http://www.abilitiessoft.com Madison, Wisconsin USA Developing software for people with disabilities _______________________________________________ xml mailing list, project page http://xmlsoft.org/ [email protected] https://mail.gnome.org/mailman/listinfo/xml
