--- parser.c.orig Mon Nov 11 20:53:30 2002 +++ parser.c Mon Nov 11 21:06:18 2002 @@ -10339,30 +10339,40 @@ } /** - * xmlSAXParseMemory: + * xmlSAXParseMemoryWithData: * @sax: the SAX handler block * @buffer: an pointer to a char array * @size: the size of the array - * @recovery: work in recovery mode, i.e. tries to read not Well Formed + * @recovery: work in recovery mode, i.e. tries to read no Well Formed * documents + * @data: the userdata * * parse an XML in-memory block and use the given SAX function block * to handle the parsing callback. If sax is NULL, fallback to the default * DOM tree building routines. - * + * + * User data (void *) is stored within the parser context in the + * context's _private member, so it is available nearly everywhere in libxml + * * Returns the resulting document tree */ + xmlDocPtr -xmlSAXParseMemory(xmlSAXHandlerPtr sax, const char *buffer, - int size, int recovery) { +xmlSAXParseMemoryWithData(xmlSAXHandlerPtr sax, const char *buffer, + int size, int recovery, void *data) { xmlDocPtr ret; xmlParserCtxtPtr ctxt; ctxt = xmlCreateMemoryParserCtxt(buffer, size); if (ctxt == NULL) return(NULL); if (sax != NULL) { + if (ctxt->sax != NULL) + xmlFree(ctxt->sax); ctxt->sax = sax; } + if (data!=NULL) { + ctxt->_private=data; + } xmlParseDocument(ctxt); @@ -10380,6 +10390,26 @@ } /** + * xmlSAXParseMemory: + * @sax: the SAX handler block + * @buffer: an pointer to a char array + * @size: the size of the array + * @recovery: work in recovery mode, i.e. tries to read not Well Formed + * documents + * + * parse an XML in-memory block and use the given SAX function block + * to handle the parsing callback. If sax is NULL, fallback to the default + * DOM tree building routines. + * + * Returns the resulting document tree + */ +xmlDocPtr +xmlSAXParseMemory(xmlSAXHandlerPtr sax, const char *buffer, + int size, int recovery) { + return xmlSAXParseMemoryWithData(sax, buffer, size, recovery, NULL); +} + +/** * xmlParseMemory: * @buffer: an pointer to a char array * @size: the size of the array --- include/libxml/parser.h.orig Mon Nov 11 21:07:39 2002 +++ include/libxml/parser.h Mon Nov 11 21:10:40 2002 @@ -734,6 +734,11 @@ const char *buffer, int size, int recovery); +xmlDocPtr xmlSAXParseMemoryWithData (xmlSAXHandlerPtr sax, + const char *buffer, + int size, + int recovery, + void *data); xmlDocPtr xmlSAXParseFile (xmlSAXHandlerPtr sax, const char *filename, int recovery);