fixed the initialization of the SAX structure which was breaking xsltproc

* parserInternals.c: fixed the initialization of the SAX structure
  which was breaking xsltproc
* xpath.c: patch from Petr Pajas for CDATA nodes
* tree.c: patch from Petr Pajas improving xmlGetNodePath()
* parser.c include/libxml/parser.h: patch from Peter Jones
  removing a leak in xmlSAXParseMemory() and adding the
  function xmlSAXParseMemoryWithData()
Daniel
This commit is contained in:
Daniel Veillard 2002-11-12 12:36:52 +00:00
parent f854d99fbd
commit 8606bbbc0a
6 changed files with 159 additions and 26 deletions

View File

@ -1,3 +1,13 @@
Tue Nov 12 13:32:50 CET 2002 Daniel Veillard <daniel@veillard.com>
* parserInternals.c: fixed the initialization of the SAX structure
which was breaking xsltproc
* xpath.c: patch from Petr Pajas for CDATA nodes
* tree.c: patch from Petr Pajas improving xmlGetNodePath()
* parser.c include/libxml/parser.h: patch from Peter Jones
removing a leak in xmlSAXParseMemory() and adding the
function xmlSAXParseMemoryWithData()
Mon Nov 11 20:47:03 MST 2002 John Fleck <jfleck@inkstain.net>
adding pdf of tutorial, changing web page to link to it

View File

@ -734,6 +734,11 @@ xmlDocPtr xmlSAXParseMemory (xmlSAXHandlerPtr sax,
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);

View File

@ -10338,6 +10338,57 @@ xmlCreateMemoryParserCtxt(const char *buffer, int size) {
return(ctxt);
}
/**
* 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 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
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);
if ((ctxt->wellFormed) || recovery) ret = ctxt->myDoc;
else {
ret = NULL;
xmlFreeDoc(ctxt->myDoc);
ctxt->myDoc = NULL;
}
if (sax != NULL)
ctxt->sax = NULL;
xmlFreeParserCtxt(ctxt);
return(ret);
}
/**
* xmlSAXParseMemory:
* @sax: the SAX handler block
@ -10355,28 +10406,7 @@ xmlCreateMemoryParserCtxt(const char *buffer, int size) {
xmlDocPtr
xmlSAXParseMemory(xmlSAXHandlerPtr sax, const char *buffer,
int size, int recovery) {
xmlDocPtr ret;
xmlParserCtxtPtr ctxt;
ctxt = xmlCreateMemoryParserCtxt(buffer, size);
if (ctxt == NULL) return(NULL);
if (sax != NULL) {
ctxt->sax = sax;
}
xmlParseDocument(ctxt);
if ((ctxt->wellFormed) || recovery) ret = ctxt->myDoc;
else {
ret = NULL;
xmlFreeDoc(ctxt->myDoc);
ctxt->myDoc = NULL;
}
if (sax != NULL)
ctxt->sax = NULL;
xmlFreeParserCtxt(ctxt);
return(ret);
return xmlSAXParseMemoryWithData(sax, buffer, size, recovery, NULL);
}
/**

View File

@ -2250,7 +2250,7 @@ xmlInitParserCtxt(xmlParserCtxtPtr ctxt)
ctxt->space = &ctxt->spaceTab[0];
ctxt->sax = sax;
initxmlDefaultSAXHandler(sax, xmlGetWarningsDefaultValue);
memcpy(sax, &xmlDefaultSAXHandler, sizeof(xmlSAXHandler));
ctxt->userData = ctxt;
ctxt->myDoc = NULL;

90
tree.c
View File

@ -3493,8 +3493,9 @@ xmlGetNodePath(xmlNodePtr node)
}
if (occur == 0) {
tmp = cur->next;
while (tmp != NULL) {
if (xmlStrEqual(cur->name, tmp->name))
while (tmp != NULL && occur == 0) {
if ((tmp->type == XML_ELEMENT_NODE) &&
(xmlStrEqual(cur->name, tmp->name)))
occur++;
tmp = tmp->next;
}
@ -3502,6 +3503,91 @@ xmlGetNodePath(xmlNodePtr node)
occur = 1;
} else
occur++;
} else if (cur->type == XML_COMMENT_NODE) {
sep = "/";
name = "comment()";
next = cur->parent;
/*
* Thumbler index computation
*/
tmp = cur->prev;
while (tmp != NULL) {
if (tmp->type == XML_COMMENT_NODE)
occur++;
tmp = tmp->prev;
}
if (occur == 0) {
tmp = cur->next;
while (tmp != NULL && occur == 0) {
if (tmp->type == XML_COMMENT_NODE)
occur++;
tmp = tmp->next;
}
if (occur != 0)
occur = 1;
} else
occur++;
} else if ((cur->type == XML_TEXT_NODE) ||
(cur->type == XML_CDATA_SECTION_NODE)) {
sep = "/";
name = "text()";
next = cur->parent;
/*
* Thumbler index computation
*/
tmp = cur->prev;
while (tmp != NULL) {
if ((cur->type == XML_TEXT_NODE) ||
(cur->type == XML_CDATA_SECTION_NODE))
occur++;
tmp = tmp->prev;
}
if (occur == 0) {
tmp = cur->next;
while (tmp != NULL && occur == 0) {
if ((cur->type == XML_TEXT_NODE) ||
(cur->type == XML_CDATA_SECTION_NODE))
occur++;
tmp = tmp->next;
}
if (occur != 0)
occur = 1;
} else
occur++;
} else if (cur->type == XML_PI_NODE) {
sep = "/";
snprintf(nametemp, sizeof(nametemp) - 1,
"processing-instruction('%s')", cur->name);
nametemp[sizeof(nametemp) - 1] = 0;
name = nametemp;
next = cur->parent;
/*
* Thumbler index computation
*/
tmp = cur->prev;
while (tmp != NULL) {
if ((tmp->type == XML_PI_NODE) &&
(xmlStrEqual(cur->name, tmp->name)))
occur++;
tmp = tmp->prev;
}
if (occur == 0) {
tmp = cur->next;
while (tmp != NULL && occur == 0) {
if ((tmp->type == XML_PI_NODE) &&
(xmlStrEqual(cur->name, tmp->name)))
occur++;
tmp = tmp->next;
}
if (occur != 0)
occur = 1;
} else
occur++;
} else if (cur->type == XML_ATTRIBUTE_NODE) {
sep = "/@";
name = (const char *) (((xmlAttrPtr) cur)->name);

View File

@ -9336,7 +9336,9 @@ xmlXPathNodeCollectAndTestNth(xmlXPathParserContextPtr ctxt,
(cur->type == XML_PI_NODE) ||
(cur->type == XML_COMMENT_NODE) ||
(cur->type == XML_CDATA_SECTION_NODE) ||
(cur->type == XML_TEXT_NODE)))) {
(cur->type == XML_TEXT_NODE))) ||
((type == NODE_TYPE_TEXT) &&
(cur->type == XML_CDATA_SECTION_NODE))) {
n++;
if (n == indx)
addNode(list, cur);