[Expat-discuss] Expat's XML_Parse() method does not return

James Kim jkim202 at aucklanduni.ac.nz
Sun Jul 27 02:13:24 CEST 2008


Hi!

I am using Expat to parse XML files. I have implemented start/end/data handlers for my parser. My parser is able to parse XML files, but it does not return after it has completed parsing. When I tracked down the problem, the cause was XML_Parse that does not return in its final call. I have checked that "done" changes to true on its final call. The final call to XML_Parse does not throw any exceptions, it is simply stuck. Below is the method which calls XML_Parse(). Any help would be appreciated. Thank you.


  1.. void
  2.. XMLParser::ParseXML(BFile* file)
  3.. {
  4..     char msg[1024];
  5..     
  6..     XML_Parser parser = XML_ParserCreate(NULL);
  7..     XML_SetUserData(parser, this);
  8..     XML_SetElementHandler(parser, StartElementHandler, EndElementHandler);
  9..     XML_SetCharacterDataHandler(parser, CharDataHandler);
  10..     
  11..     bool done = false;
  12..     do {
  13..         ssize_t len = file->Read(fBuffer, BUFSIZ);
  14..         if (len < BUFSIZ) {
  15..             done = true;
  16..         }
  17..         if (!XML_Parse(parser, fBuffer, len, done)) {
  18..             sprintf(msg, "%s at line %d\n",
  19..                     XML_ErrorString(XML_GetErrorCode(parser)),
  20..                     XML_GetCurrentLineNumber(parser));
  21..             printf(msg);
  22..         }
  23..     } while (!done);
  24..     
  25..     XML_ParserFree(parser);
  26.. }

Regards,
James Kim


More information about the Expat-discuss mailing list