Re: [xml] When will be xmlTextReaderReadString implemented
- From: Bjorn Reese <breese mail1 stofanet dk>
- To: Jirka Kosek <jirka kosek cz>
- Cc: xml gnome org
- Subject: Re: [xml] When will be xmlTextReaderReadString implemented
- Date: Thu, 27 Jan 2005 20:12:07 +0100
Jirka Kosek wrote:
are there any estimate when xmlTextReaderReadString could be
implemented? Pull-mode parser without this function is not very usable
Here you go...
Index: xmlreader.c
===================================================================
RCS file: /cvs/gnome/gnome-xml/xmlreader.c,v
retrieving revision 1.114
diff -u -p -u -r1.114 xmlreader.c
--- xmlreader.c 4 Jan 2005 17:50:08 -0000 1.114
+++ xmlreader.c 27 Jan 2005 19:05:11 -0000
@@ -1164,6 +1164,44 @@ xmlTextReaderDoExpand(xmlTextReaderPtr r
}
/**
+ * 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,27 @@ xmlTextReaderReadOuterXml(xmlTextReaderP
* 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:
+ return xmlTextReaderCollectSiblings(node->children);
+ case XML_ATTRIBUTE_NODE:
+ TODO
+ break;
+ default:
+ break;
+ }
return(NULL);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]