[Expat-discuss] Exiting expat handlers

Artyom S. Bolgar abolgar@mail.natm.ru
Mon Oct 28 21:42:24 2002


I use the setjmp/longjmp for these purposes. Something like that:
===
  jmp_buf mark; // global, or accessible from handlers
.......

  XML_Parser pparser = XML_ParserCreate (NULL);
  XML_SetUserData(pparser, &valueS);
  XML_SetElementHandler(pparser, ........);
  XML_SetCharacterDataHandler(pparser, .........);

  jmpret = setjmp(mark);
  if (jmpret == 0) { // not error
      if (XML_Parse (pparser, ASN1BUFPTR(pctxt), pctxt->buffer.size, TRUE)
== 0) { // is error occured?
          // parser's error handling here
      }
   }
   else { //error! i.e. longjmp invoked
    ... do something or nothing .....
   }
   XML_ParserFree (pparser);
===

Inside the handlers to raise an "exception" call longjmp:

longjmp(mark, stat); // stat is error code, any integers

Yours sincerely.
   Artyom Bolgar.
   Objective Systems, Inc.
   http://www.obj-sys.com

----- Original Message -----
From: "Ken Johnston" <klj@donnell.com>
To: <expat-discuss@libexpat.org>
Sent: Tuesday, October 29, 2002 12:10 AM
Subject: [Expat-discuss] Exiting expat handlers


> Josh,
>
> I would be very interested in finding out about option b). Is there any
> way in ANSI C (not C++) for a handler which detects an application error
> to cause XML_Parse to abort parsing and return immediately to the caller
> (of XML_Parse)? It doesn't have to return with an error or clean up the
> parse object. That could all be flagged in the user data from the
> handler that found the error.
>
> Thanks,
> - Ken Johnston
>
> >> From: "Firas Abughazaleh" <firas@apexion.com>
> >> Date: Thu, 17 Oct 2002 12:46:36 +0300
> >> Hi all,
> >>
> >> Anyone knows how can you exit an instance of expat gracefully if you
> were
> >inside an element handler and you encountered an error inside it?
> >>
> >> Thanks,
> >> - Firas
> >
> >Firas,
> >
> >Do you mean a) exiting the handler, b) terminating parsing and killing
> the
> >parser (object), or c) terminating the program?
> >
> > - Josh Martin
>
>
>
>
>
> _______________________________________________
> Expat-discuss mailing list
> Expat-discuss@libexpat.org
> http://mail.libexpat.org/mailman-21/listinfo/expat-discuss
>