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

implementation of xmlTextReaderReadString by Bjorn Reese Daniel

* xmlreader.c: implementation of xmlTextReaderReadString by
  Bjorn Reese
Daniel
parent 87250a97
Fri Jan 28 18:37:18 CET 2005 Daniel Veillard <daniel@veillard.com>
* xmlreader.c: implementation of xmlTextReaderReadString by
Bjorn Reese
Fri Jan 28 16:51:47 CET 2005 Kasimier Buchcik <libxml2-cvs@cazic.net>
 
* xmlschemas.c: Corrected an ambigious symbol-space for
......
......@@ -1163,6 +1163,44 @@ xmlTextReaderDoExpand(xmlTextReaderPtr reader) {
return(1);
}
/**
* xmlTextReaderCollectSiblings:
* @node: the first child
*
* Traverse depth-first through all sibling nodes and their children
* nodes and concatenate their content. This is an auxiliary function
* to xmlTextReaderReadString.
*
* Returns a string containing the content, or NULL in case of error.
*/
static xmlChar *
xmlTextReaderCollectSiblings(xmlNodePtr node)
{
xmlBufferPtr buffer;
xmlChar *ret;
buffer = xmlBufferCreate();
if (buffer == NULL)
return NULL;
for ( ; node != NULL; node = node->next) {
switch (node->type) {
case XML_TEXT_NODE:
case XML_CDATA_SECTION_NODE:
xmlBufferCat(buffer, node->content);
break;
case XML_ELEMENT_NODE:
xmlBufferCat(buffer, xmlTextReaderCollectSiblings(node->children));
default:
break;
}
}
ret = buffer->content;
buffer->content = NULL;
xmlBufferFree(buffer);
return(ret);
}
/**
* xmlTextReaderRead:
* @reader: the xmlTextReaderPtr used
......@@ -1606,8 +1644,29 @@ xmlTextReaderReadOuterXml(xmlTextReaderPtr reader ATTRIBUTE_UNUSED) {
* The string must be deallocated by the caller.
*/
xmlChar *
xmlTextReaderReadString(xmlTextReaderPtr reader ATTRIBUTE_UNUSED) {
TODO
xmlTextReaderReadString(xmlTextReaderPtr reader)
{
xmlNodePtr node;
if ((reader == NULL) || (reader->node == NULL))
return(NULL);
node = (reader->curnode != NULL) ? reader->curnode : reader->node;
switch (node->type) {
case XML_TEXT_NODE:
if (node->content != NULL)
return(xmlStrdup(node->content));
break;
case XML_ELEMENT_NODE:
if (xmlTextReaderDoExpand(reader) != -1) {
return xmlTextReaderCollectSiblings(node->children);
}
case XML_ATTRIBUTE_NODE:
TODO
break;
default:
break;
}
return(NULL);
}
......
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