diff --git a/ChangeLog b/ChangeLog index 98906a07..24774f52 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +Thu Jul 12 21:20:17 CEST 2001 Daniel Veillard + + * 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 * .cvsignore: diff --git a/DOCBparser.c b/DOCBparser.c index 4a07496e..ef533391 100644 --- a/DOCBparser.c +++ b/DOCBparser.c @@ -2458,7 +2458,8 @@ static int areBlanks(docbParserCtxtPtr ctxt, const xmlChar *str, int len) { 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 bcf4394e..ea244f52 100644 --- a/HTMLparser.c +++ b/HTMLparser.c @@ -1782,7 +1782,8 @@ static int areBlanks(htmlParserCtxtPtr ctxt, const xmlChar *str, int len) { 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 54614078..6ad48e36 100644 --- a/HTMLtree.c +++ b/HTMLtree.c @@ -538,7 +538,8 @@ htmlNodeDumpFormat(xmlBufferPtr buf, xmlDocPtr doc, xmlNodePtr cur, } 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 @@ htmlNodeDumpFormat(xmlBufferPtr buf, xmlDocPtr doc, xmlNodePtr cur, 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 @@ htmlNodeDumpFormatOutput(xmlOutputBufferPtr buf, xmlDocPtr doc, } 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 @@ htmlNodeDumpFormatOutput(xmlOutputBufferPtr buf, xmlDocPtr doc, 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 87b25b19..73e04b84 100644 --- a/SAX.c +++ b/SAX.c @@ -966,6 +966,8 @@ startElement(void *ctx, const xmlChar *fullname, const xmlChar **atts) 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 92d71cb2..a36ad03a 100644 --- a/debugXML.c +++ b/debugXML.c @@ -248,7 +248,8 @@ xmlDebugDumpElemDecl(FILE *output, xmlElementPtr elem, int depth) { 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 @@ void xmlDebugDumpOneNode(FILE *output, xmlNodePtr node, int depth) { 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 @@ xmlDebugDumpEntityCallback(xmlEntityPtr cur, FILE *output) { 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 9e4c3f85..b5f6302d 100644 --- a/include/libxml/tree.h +++ b/include/libxml/tree.h @@ -405,6 +405,9 @@ struct _xmlNode { 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 b3a0b1cf..4f8b07a2 100644 --- a/parser.c +++ b/parser.c @@ -1477,7 +1477,8 @@ static int areBlanks(xmlParserCtxtPtr ctxt, const xmlChar *str, int len) { 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 db225911..6be2c05b 100644 --- a/tree.c +++ b/tree.c @@ -904,7 +904,8 @@ xmlNodeListGetRawString(xmlDocPtr doc, xmlNodePtr list, int inLine) { 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 @@ xmlAddChild(xmlNodePtr parent, xmlNodePtr cur) { /* * 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 @@ xmlAddChild(xmlNodePtr parent, xmlNodePtr cur) { } /* - * 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(xmlNodePtr cur) { 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 @@ xmlFreeNode(xmlNodePtr cur) { 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 @@ xmlStaticCopyNode(xmlNodePtr node, xmlDocPtr doc, xmlNodePtr parent, 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 @@ -2900,32 +2904,6 @@ xmlNodePtr xmlCopyNodeList(xmlNodePtr node) { return(ret); } -/** - * 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 @@ xmlNodeGetContent(xmlNodePtr cur) { 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 @@ xmlNodeSetContent(xmlNodePtr cur, const xmlChar *content) { 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 @@ xmlNodeSetContentLen(xmlNodePtr cur, const xmlChar *content, int len) { 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 @@ xmlNodeAddContentLen(xmlNodePtr cur, const xmlChar *content, int len) { 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 @@ xmlIsBlankNode(xmlNodePtr node) { 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 @@ xmlNodeDump(xmlBufferPtr buf, xmlDocPtr doc, xmlNodePtr cur, int level, 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 @@ xmlNodeDumpOutput(xmlOutputBufferPtr buf, xmlDocPtr doc, xmlNodePtr cur, 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 c4d97203..5192fe50 100644 --- a/xpointer.c +++ b/xpointer.c @@ -1421,7 +1421,8 @@ xmlXPtrBuildRangeNodeList(xmlXPathObjectPtr range) { } } 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 @@ xmlXPtrAdvanceChar(xmlNodePtr *node, int *indx, int bytes) { * 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 @@ xmlXPtrMatchString(const xmlChar *string, xmlNodePtr start, int startindex, 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 @@ xmlXPtrSearchString(const xmlChar *string, xmlNodePtr *start, int *startindex, 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 @@ xmlXPtrGetLastChar(xmlNodePtr *node, int *indx) { 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