[Expat-discuss] How to use XML_ParserReset for re-enty ?
안계진
gye_jin at hotmail.com
Thu Dec 4 22:15:00 EST 2003
Hi all,
I'm a new user of expat XML parser,
when I'm trying to parser twice (re-entry), I think it is right to use XML_ParserReset.
but, there's an error reported like "junk after document element"..
I don't sure to use XML_ParserReset function.
the following is my outline.c example
int
main(int argc, char *argv[])
{
XML_Parser p = XML_ParserCreate(NULL);
if (! p) {
fprintf(stderr, "Couldn't allocate memory for parser\n");
exit(-1);
}
XML_SetElementHandler(p, start, end);
for (;;) {
int done;
int len;
len = fread(Buff, 1, BUFFSIZE, stdin);
if (ferror(stdin)) {
fprintf(stderr, "Read error\n");
exit(-1);
}
done = feof(stdin);
if (XML_Parse(p, Buff, len, done) == XML_STATUS_ERROR) {
fprintf(stderr, "Parse error at line %d:\n%s\n",
XML_GetCurrentLineNumber(p),
XML_ErrorString(XML_GetErrorCode(p)));
XML_ParserReset(p,NULL); // if there is error, Clean up the memory structures so that it may be used again.
//exit(-1);
}
if (done)
break;
}
return 0;
}
More information about the Expat-discuss
mailing list