Hi
I'm having trouble parsing more than one document with the SAX
interface. I can parse the first one fine, using xmlParseChunk, and set
terminate=1 to indicate that this is the final chunk from that document,
and xmlParseChunk returns success. Then I try to parse a second
document, and none of the event handlers are triggered for that
document, but xmlParseChunk still returns success for that document.
Do I need to do something else, as well as setting terminate=1, to
indicate the end of the first document?
I've reduced the problem to this sample program:
#include "libxml/parser.h"
#include "libxml/HTMLparser.h"
#include "stdlib.h"
#include "string.h"
static xmlSAXHandler SAXHandler;
static xmlParserCtxtPtr XMLParser;
void fnCharacterHandler(void *userData, const xmlChar *s /*not
null-terminated - use len*/, int len)
{
printf("character handler\n");
}
int main(void)
{
char * doc1 = "<Doc>Text 1</Doc>";
char * doc2 = "<Doc>Text 2</Doc>";
int ret;
SAXHandler.characters = fnCharacterHandler;
XMLParser = xmlCreatePushParserCtxt(&SAXHandler, NULL, NULL, 0, NULL);
ret = xmlParseChunk(XMLParser, doc1, strlen(doc1), 1 /*terminate*/);
printf("return value from parsing doc1: %d\n", ret);
ret = xmlParseChunk(XMLParser, doc2, strlen(doc2), 1 /*terminate*/);
printf("return value from parsing doc2: %d\n", ret);
return 0;
}
When I run that I get this output:
character handler
return value from parsing doc1: 0
return value from parsing doc2: 0
but I'd expect to get:
character handler
return value from parsing doc1: 0
character handler
return value from parsing doc2: 0
i.e. I'd expect the character handler to be called when parsing the
second document too. What do I need to do differently?
Thanks,
Rachael
_______________________________________________
xml mailing list, project page http://xmlsoft.org/
[email protected]
http://mail.gnome.org/mailman/listinfo/xml