Commit c469692e authored by Daniel Veillard's avatar Daniel Veillard
Browse files

cleanup xmlNodeGetContent() reusing xmlNodeBufGetContent(), tested it

* tree.c: cleanup xmlNodeGetContent() reusing xmlNodeBufGetContent(),
  tested it through the xslt regression suite.
Daniel
parent 7869729c
Sun Oct 19 23:46:04 CEST 2003 Daniel Veillard <daniel@veillard.com>
* tree.c: cleanup xmlNodeGetContent() reusing xmlNodeBufGetContent(),
tested it through the xslt regression suite.
Sun Oct 19 22:42:16 CEST 2003 Daniel Veillard <daniel@veillard.com>
 
* tree.c include/libxml/tree.h: adding xmlNodeBufGetContent()
......
......@@ -4868,65 +4868,13 @@ xmlNodeGetContent(xmlNodePtr cur)
switch (cur->type) {
case XML_DOCUMENT_FRAG_NODE:
case XML_ELEMENT_NODE:{
xmlNodePtr tmp = cur;
xmlBufferPtr buffer;
xmlChar *ret;
buffer = xmlBufferCreateSize(64);
if (buffer == NULL)
return (NULL);
while (tmp != NULL) {
switch (tmp->type) {
case XML_CDATA_SECTION_NODE:
case XML_TEXT_NODE:
if (tmp->content != NULL)
xmlBufferCat(buffer, tmp->content);
break;
case XML_ENTITY_REF_NODE:{
/* recursive substitution of entity references */
xmlChar *cont = xmlNodeGetContent(tmp);
if (cont) {
xmlBufferCat(buffer,
(const xmlChar *) cont);
xmlFree(cont);
}
break;
}
default:
break;
}
/*
* Skip to next node
*/
if (tmp->children != NULL) {
if (tmp->children->type != XML_ENTITY_DECL) {
tmp = tmp->children;
continue;
}
}
if (tmp == cur)
break;
if (tmp->next != NULL) {
tmp = tmp->next;
continue;
}
do {
tmp = tmp->parent;
if (tmp == NULL)
break;
if (tmp == cur) {
tmp = NULL;
break;
}
if (tmp->next != NULL) {
tmp = tmp->next;
break;
}
} while (tmp != NULL);
}
xmlNodeBufGetContent(buffer, cur);
ret = buffer->content;
buffer->content = NULL;
xmlBufferFree(buffer);
......@@ -4949,7 +4897,6 @@ xmlNodeGetContent(xmlNodePtr cur)
return (NULL);
case XML_ENTITY_REF_NODE:{
xmlEntityPtr ent;
xmlNodePtr tmp;
xmlBufferPtr buffer;
xmlChar *ret;
......@@ -4962,21 +4909,7 @@ xmlNodeGetContent(xmlNodePtr cur)
if (buffer == NULL)
return (NULL);
/* an entity content can be any "well balanced chunk",
* i.e. the result of the content [43] production:
* http://www.w3.org/TR/REC-xml#NT-content
* -> we iterate through child nodes and recursive call
* xmlNodeGetContent() which handles all possible node types */
tmp = ent->children;
while (tmp) {
xmlChar *cont = xmlNodeGetContent(tmp);
if (cont) {
xmlBufferCat(buffer, (const xmlChar *) cont);
xmlFree(cont);
}
tmp = tmp->next;
}
xmlNodeBufGetContent(buffer, cur);
ret = buffer->content;
buffer->content = NULL;
......@@ -4995,27 +4928,19 @@ xmlNodeGetContent(xmlNodePtr cur)
case XML_DOCB_DOCUMENT_NODE:
#endif
case XML_HTML_DOCUMENT_NODE: {
xmlChar *tmp;
xmlChar *res = NULL;
xmlBufferPtr buffer;
xmlChar *ret;
cur = cur->children;
while (cur!= NULL) {
if ((cur->type == XML_ELEMENT_NODE) ||
(cur->type == XML_TEXT_NODE) ||
(cur->type == XML_CDATA_SECTION_NODE)) {
tmp = xmlNodeGetContent(cur);
if (tmp != NULL) {
if (res == NULL)
res = tmp;
else {
res = xmlStrcat(res, tmp);
xmlFree(tmp);
}
}
}
cur = cur->next;
}
return(res);
buffer = xmlBufferCreate();
if (buffer == NULL)
return (NULL);
xmlNodeBufGetContent(buffer, (xmlNodePtr) cur);
ret = buffer->content;
buffer->content = NULL;
xmlBufferFree(buffer);
return (ret);
}
case XML_NAMESPACE_DECL: {
xmlChar *tmp;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment