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
diff --git a/ChangeLog b/ChangeLog
index c014f32..8b7bb30 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -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
diff --git a/include/libxml/parser.h b/include/libxml/parser.h
index a1c8b37..a54b6d9 100644
--- a/include/libxml/parser.h
+++ b/include/libxml/parser.h
@@ -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);
diff --git a/parser.c b/parser.c
index 304dc67..f6363ae 100644
--- a/parser.c
+++ b/parser.c
@@ -10339,6 +10339,57 @@
}
/**
+ * 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
* @buffer: an pointer to a char array
@@ -10355,28 +10406,7 @@
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);
}
/**
diff --git a/parserInternals.c b/parserInternals.c
index 41725d5..c09fc95 100644
--- a/parserInternals.c
+++ b/parserInternals.c
@@ -2250,7 +2250,7 @@
ctxt->space = &ctxt->spaceTab[0];
ctxt->sax = sax;
- initxmlDefaultSAXHandler(sax, xmlGetWarningsDefaultValue);
+ memcpy(sax, &xmlDefaultSAXHandler, sizeof(xmlSAXHandler));
ctxt->userData = ctxt;
ctxt->myDoc = NULL;
diff --git a/tree.c b/tree.c
index 44ea7a5..26276ca 100644
--- a/tree.c
+++ b/tree.c
@@ -3493,8 +3493,9 @@
}
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 @@
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);
diff --git a/xpath.c b/xpath.c
index fc884aa..5da280f 100644
--- a/xpath.c
+++ b/xpath.c
@@ -9336,7 +9336,9 @@
(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);