I have created an xmlParserCtxtPtr
with libxml2's xmlCreatePushParserCtxt
, passing a pointer to a custom xmlSAXHandler
in the process.
I then read a line from an XML document file stream into a character buffer, replacing the end of line character with a \0
null termination character.
This chars
buffer is then being passed as follows:
xmlParseChunk(pParserCtxt, chars, numChars, 0);
numChars
is the number of characters from the start of the buffer, up to and including the null termination character.
My issue is that none of the SAX handlers are being called, and the xmlParseChunk
function is returning the following enumerated error (47):
XML_ERR_PI_NOT_FINISHED
This occurs for every chunk that is passed in the chars buffer, but I believe the parser is stuck in an error state from the initial null terminated string that it processed:
<?xml version="1.0" encoding="UTF-8"?>
As the documentation for the libxml2 library is sparse, as are its inline comments, I was hoping someone with more experience with the library could point out my error?
Thank you for taking a look.
You must not pass NUL characters to xmlParseChunk
. Simply pass chunks without a terminating character. There's a size
parameter to pass the length of a chunk.