[xml] overriding error handler



I'm having trouble overriding the error handler in
xmlDefaultSAXHandler.  To make it easier to show what I'm trying, I
just modified the gjobread example with what I think is the correct
stuff:

*** gjobread.c.orig     Thu Jan 10 11:14:55 2002
--- gjobread.c  Thu Jan 10 11:21:00 2002
***************
*** 175,180 ****
--- 175,186 ----
      jobPtr jobs[500]; /* using dynamic alloc is left as an exercise */
  } gJob, *gJobPtr;
  
+ static void
+ handle_parser_error(void* ctx, const char* msg, ...)
+ {
+   fputs("handle_parser_error called\n", stderr);
+   exit(1);
+ }
  
  static gJobPtr
  parseGjobFile(char *filename) {
***************
*** 183,188 ****
--- 189,199 ----
      jobPtr curjob;
      xmlNsPtr ns;
      xmlNodePtr cur;
+ 
+     xmlInitParser();
+     xmlDefaultSAXHandler.warning = handle_parser_error;
+     xmlDefaultSAXHandler.error = handle_parser_error;
+     xmlDefaultSAXHandler.fatalError = handle_parser_error;
  
      /*
       * build an XML tree from a the file;

      [calls xmlParseFile()]


The way I'm reading the source, this should work.  But apparently I'm
not seeing some place where xmlDefaultSAXHandler is being
reinitialized because when I run it on a broken gjobs.xml file I get:

[~/src/xml/libxml2-2.4.12/example]0$ ./gjobread gjobs.xml 
gjobs.xml:2: error: Start tag expected, '<' not found
gjob:Helping xmlns:gjob="http://www.gnome.org/some-location";>
^
Error parsing file 'gjobs.xml'

This is on Solaris 8 and configured with default options (i.e. no
with-threads).

Steve



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