store the line numbder in element->content, may break some software, need

* DOCBparser.c HTMLparser.c HTMLtree.c SAX.c debugXML.c parser.c
  tree.c xpointer.c: store the line numbder in element->content,
  may break some software, need a configuration mechanism
Daniel
diff --git a/ChangeLog b/ChangeLog
index 98906a0..24774f5 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+Thu Jul 12 21:20:17 CEST 2001 Daniel Veillard <Daniel.Veillard@imag.fr>
+
+	* DOCBparser.c HTMLparser.c HTMLtree.c SAX.c debugXML.c parser.c
+	  tree.c xpointer.c: store the line numbder in element->content,
+	  may break some software, need a configuration mechanism
+
 2001-07-10  Darin Adler  <darin@bentspoon.com>
 
 	* .cvsignore:
diff --git a/DOCBparser.c b/DOCBparser.c
index 4a07496..ef53339 100644
--- a/DOCBparser.c
+++ b/DOCBparser.c
@@ -2458,7 +2458,8 @@
     if (ctxt->node == NULL) return(0);
     lastChild = xmlGetLastChild(ctxt->node);
     if (lastChild == NULL) {
-        if (ctxt->node->content != NULL) return(0);
+        if ((ctxt->node->type != XML_ELEMENT_NODE) &&
+	    (ctxt->node->content != NULL)) return(0);
     } else if (xmlNodeIsText(lastChild))
         return(0);
     return(1);
diff --git a/HTMLparser.c b/HTMLparser.c
index bcf4394..ea244f5 100644
--- a/HTMLparser.c
+++ b/HTMLparser.c
@@ -1782,7 +1782,8 @@
     if (ctxt->node == NULL) return(0);
     lastChild = xmlGetLastChild(ctxt->node);
     if (lastChild == NULL) {
-        if (ctxt->node->content != NULL) return(0);
+        if ((ctxt->node->type != XML_ELEMENT_NODE) &&
+            (ctxt->node->content != NULL)) return(0);
     } else if (xmlNodeIsText(lastChild)) {
         return(0);
     } else if (xmlStrEqual(lastChild->name, BAD_CAST"b")) {
diff --git a/HTMLtree.c b/HTMLtree.c
index 5461407..6ad48e3 100644
--- a/HTMLtree.c
+++ b/HTMLtree.c
@@ -538,7 +538,8 @@
 	}
 	return;
     }
-    if ((cur->content == NULL) && (cur->children == NULL)) {
+    if (((cur->type == XML_ELEMENT_NODE) || (cur->content == NULL)) &&
+	(cur->children == NULL)) {
         if ((info != NULL) && (info->saveEndTag != 0) &&
 	    (xmlStrcmp(BAD_CAST info->name, BAD_CAST "html")) &&
 	    (xmlStrcmp(BAD_CAST info->name, BAD_CAST "body"))) {
@@ -557,7 +558,7 @@
 	return;
     }
     xmlBufferWriteChar(buf, ">");
-    if (cur->content != NULL) {
+    if ((cur->type != XML_ELEMENT_NODE) && (cur->content != NULL)) {
 	xmlChar *buffer;
 
 #ifndef XML_USE_BUFFER_CONTENT
@@ -1039,7 +1040,8 @@
 	}
 	return;
     }
-    if ((cur->content == NULL) && (cur->children == NULL)) {
+    if (((cur->type == XML_ELEMENT_NODE) || (cur->content == NULL)) &&
+	(cur->children == NULL)) {
         if ((info != NULL) && (info->saveEndTag != 0) &&
 	    (xmlStrcmp(BAD_CAST info->name, BAD_CAST "html")) &&
 	    (xmlStrcmp(BAD_CAST info->name, BAD_CAST "body"))) {
@@ -1060,7 +1062,8 @@
 	return;
     }
     xmlOutputBufferWriteString(buf, ">");
-    if (cur->content != NULL) {
+    if ((cur->type != XML_ELEMENT_NODE) &&
+	(cur->content != NULL)) {
 	    /*
 	     * Uses the OutputBuffer property to automatically convert
 	     * invalids to charrefs
diff --git a/SAX.c b/SAX.c
index 87b25b1..73e04b8 100644
--- a/SAX.c
+++ b/SAX.c
@@ -966,6 +966,8 @@
         parent = ctxt->myDoc->children;
     }
     ctxt->nodemem = -1;
+    if (ctxt->input != NULL)
+	ret->content = (void *) ctxt->input->line;
 
     /*
      * We are parsing a new node.
diff --git a/debugXML.c b/debugXML.c
index 92d71cb..a36ad03 100644
--- a/debugXML.c
+++ b/debugXML.c
@@ -248,7 +248,8 @@
 	    fprintf(output, ", MIXED ");
 	    break;
     }
-    if (elem->content != NULL) {
+    if ((elem->type != XML_ELEMENT_NODE) &&
+	(elem->content != NULL)) {
 	char buf[5001];
 
 	buf[0] = 0;
@@ -602,7 +603,8 @@
     if (node->properties != NULL)
 	xmlDebugDumpAttrList(output, node->properties, depth + 1);
     if (node->type != XML_ENTITY_REF_NODE) {
-	if (node->content != NULL) {
+	if ((node->type != XML_ELEMENT_NODE) &&
+	    (node->content != NULL)) {
             shift[2 * i] = shift[2 * i + 1] = ' ' ;
             shift[2 * i + 2] = shift[2 * i + 3] = 0 ;
 	    fprintf(output, shift);
@@ -818,7 +820,8 @@
 	fprintf(output, "SYSTEM \"%s\"", cur->SystemID);
     if (cur->orig != NULL)
 	fprintf(output, "\n orig \"%s\"", cur->orig);
-    if (cur->content != NULL)
+    if ((cur->type != XML_ELEMENT_NODE) &&
+	(cur->content != NULL))
 	fprintf(output, "\n content \"%s\"", cur->content);
     fprintf(output, "\n");	
 }
diff --git a/include/libxml/tree.h b/include/libxml/tree.h
index 9e4c3f8..b5f6302 100644
--- a/include/libxml/tree.h
+++ b/include/libxml/tree.h
@@ -405,6 +405,9 @@
     xmlNs           *nsDef;     /* namespace definitions on this node */
 };
 
+#define XML_GET_CONTENT(n) ((n)->type == XML_ELEMENT_PTR ? NULL : (n)->content)
+#define XML_GET_LINE(n) ((n)->type == XML_ELEMENT_PTR ? (int) (n)->content : 0)
+
 /**
  * xmlDoc:
  *
diff --git a/parser.c b/parser.c
index b3a0b1c..4f8b07a 100644
--- a/parser.c
+++ b/parser.c
@@ -1477,7 +1477,8 @@
 
     lastChild = xmlGetLastChild(ctxt->node);
     if (lastChild == NULL) {
-        if (ctxt->node->content != NULL) return(0);
+        if ((ctxt->node->type != XML_ELEMENT_NODE) &&
+            (ctxt->node->content != NULL)) return(0);
     } else if (xmlNodeIsText(lastChild))
         return(0);
     else if ((ctxt->node->children != NULL) &&
diff --git a/tree.c b/tree.c
index db22591..6be2c05 100644
--- a/tree.c
+++ b/tree.c
@@ -904,7 +904,8 @@
     if (list == NULL) return(NULL);
 
     while (node != NULL) {
-        if (node->type == XML_TEXT_NODE) {
+        if ((node->type == XML_TEXT_NODE) ||
+	    (node->type == XML_CDATA_SECTION_NODE)) {
 	    if (inLine) {
 #ifndef XML_USE_BUFFER_CONTENT
 		ret = xmlStrcat(ret, node->content);
@@ -2248,12 +2249,10 @@
 
     /*
      * If cur is a TEXT node, merge its content with adjacent TEXT nodes
-     * or with parent->content if parent->content != NULL.
      * cur is then freed.
      */
     if (cur->type == XML_TEXT_NODE) {
-	if (((parent->type == XML_ELEMENT_NODE) || 
-	     (parent->type == XML_TEXT_NODE)) &&
+	if ((parent->type == XML_TEXT_NODE) &&
 	    (parent->content != NULL)) {
 #ifndef XML_USE_BUFFER_CONTENT
 	    xmlNodeAddContent(parent, cur->content);
@@ -2284,31 +2283,17 @@
     }
 
     /*
-     * Handle the case where parent->content != NULL, in that case it will
-     * create a intermediate TEXT node.
+     * Coalescing
      */
-    if (((parent->type == XML_ELEMENT_NODE) || (parent->type == XML_TEXT_NODE)) &&
+    if ((parent->type == XML_TEXT_NODE) &&
 	(parent->content != NULL)) {
-        xmlNodePtr text;
-	
 #ifndef XML_USE_BUFFER_CONTENT
-	text = xmlNewDocText(parent->doc, parent->content);
+	xmlNodeAddContent(parent, cur->content);
 #else
-	text = xmlNewDocText(parent->doc, xmlBufferContent(parent->content));
+	xmlNodeAddContent(parent, xmlBufferContent(cur->content));
 #endif
-	if (text != NULL) {
-	    text->next = parent->children;
-	    if (text->next != NULL)
-		text->next->prev = text;
-	    parent->children = text;
-	    UPDATE_LAST_CHILD_AND_PARENT(parent)
-#ifndef XML_USE_BUFFER_CONTENT
-	    xmlFree(parent->content);
-#else
-	    xmlBufferFree(parent->content);
-#endif
-	    parent->content = NULL;
-	}
+	xmlFreeNode(cur);
+	return(parent);
     }
     if (parent->children == NULL) {
         parent->children = cur;
@@ -2368,13 +2353,22 @@
 		xmlFreeNodeList(cur->children);
 	    if (cur->properties != NULL)
 		xmlFreePropList(cur->properties);
-	    if (cur->type != XML_ENTITY_REF_NODE)
+	    if ((cur->type != XML_ELEMENT_NODE) &&
+		(cur->type != XML_XINCLUDE_START) &&
+		(cur->type != XML_XINCLUDE_END) &&
+		(cur->type != XML_ENTITY_REF_NODE)) {
 #ifndef XML_USE_BUFFER_CONTENT
 		if (cur->content != NULL) xmlFree(cur->content);
 #else
 		if (cur->content != NULL) xmlBufferFree(cur->content);
 #endif
-	    if (cur->nsDef != NULL) xmlFreeNsList(cur->nsDef);
+	    }
+	    if (((cur->type == XML_ELEMENT_NODE) ||
+	         (cur->type == XML_XINCLUDE_START) ||
+		 (cur->type == XML_XINCLUDE_END)) &&
+		(cur->nsDef != NULL))
+		xmlFreeNsList(cur->nsDef);
+
 	    /*
 	     * When a node is a text node or a comment, it uses a global static
 	     * variable for the name of the node.
@@ -2430,12 +2424,18 @@
 	xmlFreeNodeList(cur->children);
     if (cur->properties != NULL)
 	xmlFreePropList(cur->properties);
-    if (cur->type != XML_ENTITY_REF_NODE)
+    if ((cur->type != XML_ELEMENT_NODE) &&
+	(cur->content != NULL) &&
+	(cur->type != XML_ENTITY_REF_NODE) &&
+	(cur->type != XML_XINCLUDE_END) &&
+	(cur->type != XML_XINCLUDE_START)) {
 #ifndef XML_USE_BUFFER_CONTENT
-	if (cur->content != NULL) xmlFree(cur->content);
+	xmlFree(cur->content);
 #else
-    	if (cur->content != NULL) xmlBufferFree(cur->content);
+    	xmlBufferFree(cur->content);
 #endif
+    }
+
     /*
      * When a node is a text node or a comment, it uses a global static
      * variable for the name of the node.
@@ -2756,7 +2756,11 @@
 	ret->name = xmlStringComment;
     else if (node->name != NULL)
 	ret->name = xmlStrdup(node->name);
-    if ((node->content != NULL) && (node->type != XML_ENTITY_REF_NODE)) {
+    if ((node->type != XML_ELEMENT_NODE) &&
+	(node->content != NULL) &&
+	(node->type != XML_ENTITY_REF_NODE) &&
+	(node->type != XML_XINCLUDE_END) &&
+	(node->type != XML_XINCLUDE_START)) {
 #ifndef XML_USE_BUFFER_CONTENT
 	ret->content = xmlStrdup(node->content);
 #else
@@ -2901,32 +2905,6 @@
 }
 
 /**
- * xmlCopyElement:
- * @elem:  the element
- *
- * Do a copy of the element definition.
- *
- * Returns: a new xmlElementPtr, or NULL in case of error.
-xmlElementPtr
-xmlCopyElement(xmlElementPtr elem) {
-    xmlElementPtr ret;
-
-    if (elem == NULL) return(NULL);
-    ret = xmlNewDocElement(elem->doc, elem->ns, elem->name, elem->content);
-    if (ret == NULL) return(NULL);
-    if (!recursive) return(ret);
-    if (elem->properties != NULL)
-        ret->properties = xmlCopyPropList(elem->properties);
-    
-    if (elem->nsDef != NULL)
-        ret->nsDef = xmlCopyNamespaceList(elem->nsDef);
-    if (elem->children != NULL)
-        ret->children = xmlCopyElementList(elem->children);
-    return(ret);
-}
- */
-
-/**
  * xmlCopyDtd:
  * @dtd:  the dtd
  *
@@ -3412,7 +3390,6 @@
 		return(NULL);
 	    while (tmp != NULL) {
 		switch (tmp->type) {
-		    case XML_ELEMENT_NODE: 
 		    case XML_CDATA_SECTION_NODE:
 		    case XML_TEXT_NODE:
 			if (tmp->content != NULL)
@@ -3547,14 +3524,6 @@
     switch (cur->type) {
         case XML_DOCUMENT_FRAG_NODE:
         case XML_ELEMENT_NODE:
-	    if (cur->content != NULL) {
-#ifndef XML_USE_BUFFER_CONTENT
-	        xmlFree(cur->content);
-#else
-		xmlBufferFree(cur->content);
-#endif
-		cur->content = NULL;
-	    }
 	    if (cur->children != NULL) xmlFreeNodeList(cur->children);
 	    cur->children = xmlStringGetNodeList(cur->doc, content);
 	    UPDATE_LAST_CHILD_AND_PARENT(cur)
@@ -3635,14 +3604,6 @@
     switch (cur->type) {
         case XML_DOCUMENT_FRAG_NODE:
         case XML_ELEMENT_NODE:
-	    if (cur->content != NULL) {
-#ifndef XML_USE_BUFFER_CONTENT
-	        xmlFree(cur->content);
-#else
-		xmlBufferFree(cur->content);
-#endif
-		cur->content = NULL;
-	    }
 	    if (cur->children != NULL) xmlFreeNodeList(cur->children);
 	    cur->children = xmlStringLenGetNodeList(cur->doc, content, len);
 	    UPDATE_LAST_CHILD_AND_PARENT(cur)
@@ -3721,28 +3682,9 @@
     switch (cur->type) {
         case XML_DOCUMENT_FRAG_NODE:
         case XML_ELEMENT_NODE: {
-	    xmlNodePtr last = NULL, newNode;
+	    xmlNodePtr last, newNode;
 
-	    if (cur->children != NULL) {
-		last = cur->last;
-	    } else {
-	        if (cur->content != NULL) {
-#ifndef XML_USE_BUFFER_CONTENT
-		    cur->children = xmlStringGetNodeList(cur->doc, cur->content);
-#else
-		    cur->children = xmlStringGetNodeList(cur->doc,
-			                       xmlBufferContent(cur->content));
-#endif
-		    UPDATE_LAST_CHILD_AND_PARENT(cur)
-#ifndef XML_USE_BUFFER_CONTENT
-		    xmlFree(cur->content);
-#else
-		    xmlBufferFree(cur->content);
-#endif
-		    cur->content = NULL;
-		    last = cur->last;
-		}
-	    }
+	    last = cur->last;
 	    newNode = xmlNewTextLen(content, len);
 	    if (newNode != NULL) {
 		xmlAddChild(cur, newNode);
@@ -4738,7 +4680,9 @@
     const xmlChar *cur;
     if (node == NULL) return(0);
 
-    if (node->type != XML_TEXT_NODE) return(0);
+    if ((node->type != XML_TEXT_NODE) &&
+        (node->type != XML_CDATA_SECTION_NODE))
+	return(0);
     if (node->content == NULL) return(1);
 #ifndef XML_USE_BUFFER_CONTENT
     cur = node->content;
@@ -5619,13 +5563,14 @@
     if (cur->properties != NULL)
         xmlAttrListDump(buf, doc, cur->properties);
 
-    if ((cur->content == NULL) && (cur->children == NULL) &&
+    if (((cur->type == XML_ELEMENT_NODE) || (cur->content == NULL)) &&
+	(cur->children == NULL) &&
 	(!xmlSaveNoEmptyTags)) {
         xmlBufferWriteChar(buf, "/>");
 	return;
     }
     xmlBufferWriteChar(buf, ">");
-    if (cur->content != NULL) {
+    if ((cur->type != XML_ELEMENT_NODE) && (cur->content != NULL)) {
 	xmlChar *buffer;
 
 #ifndef XML_USE_BUFFER_CONTENT
@@ -6047,13 +5992,13 @@
     if (cur->properties != NULL)
         xmlAttrListDumpOutput(buf, doc, cur->properties, encoding);
 
-    if ((cur->content == NULL) && (cur->children == NULL) &&
-	(!xmlSaveNoEmptyTags)) {
+    if (((cur->type == XML_ELEMENT_NODE) || (cur->content == NULL)) &&
+	(cur->children == NULL) && (!xmlSaveNoEmptyTags)) {
         xmlOutputBufferWriteString(buf, "/>");
 	return;
     }
     xmlOutputBufferWriteString(buf, ">");
-    if (cur->content != NULL) {
+    if ((cur->type != XML_ELEMENT_NODE) && (cur->content != NULL)) {
 	xmlChar *buffer;
 
 #ifndef XML_USE_BUFFER_CONTENT
diff --git a/xpointer.c b/xpointer.c
index c4d9720..5192fe5 100644
--- a/xpointer.c
+++ b/xpointer.c
@@ -1421,7 +1421,8 @@
 	    }
 	} else if ((cur == start) &&
 		   (list == NULL) /* looks superfluous but ... */ ) {
-	    if (cur->type == XML_TEXT_NODE) {
+	    if ((cur->type == XML_TEXT_NODE) ||
+		(cur->type == XML_CDATA_SECTION_NODE)) {
 		const xmlChar *content = cur->content;
 
 		if (content == NULL) {
@@ -2317,7 +2318,8 @@
 	 * We should have a text (or cdata) node ... 
 	 */
 	len = 0;
-	if (cur->content != NULL) {
+	if ((cur->type != XML_ELEMENT_NODE) &&
+            (cur->content != NULL)) {
 #ifndef XML_USE_BUFFER_CONTENT
 	    len = xmlStrlen(cur->content);
 #else
@@ -2383,7 +2385,8 @@
     while (stringlen > 0) {
 	if ((cur == *end) && (pos + stringlen > *endindex))
 	    return(0);
-	if (cur->content != NULL) {
+
+	if ((cur->type != XML_ELEMENT_NODE) && (cur->content != NULL)) {
 #ifndef XML_USE_BUFFER_CONTENT
 	    len = xmlStrlen(cur->content);
 #else
@@ -2481,7 +2484,7 @@
     stringlen = xmlStrlen(string);
 
     while (cur != NULL) {
-	if (cur->content != NULL) {
+	if ((cur->type != XML_ELEMENT_NODE) && (cur->content != NULL)) {
 #ifndef XML_USE_BUFFER_CONTENT
 	    len = xmlStrlen(cur->content);
 #else
@@ -2578,7 +2581,8 @@
     while (cur != NULL) {
 	if (cur->last != NULL)
 	    cur = cur->last;
-	else if (cur->content != NULL) {
+	else if ((cur->type != XML_ELEMENT_NODE) &&
+	         (cur->content != NULL)) {
 #ifndef XML_USE_BUFFER_CONTENT
 	    len = xmlStrlen(cur->content);
 #else