[libxml2] Provide new xmlBuf based saving functions
- From: Daniel Veillard <veillard src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libxml2] Provide new xmlBuf based saving functions
- Date: Fri, 3 Aug 2012 04:05:48 +0000 (UTC)
commit dddeede060f7c01788274c4f5f006d4923f9a7aa
Author: Daniel Veillard <veillard redhat com>
Date: Mon Jul 16 14:44:26 2012 +0800
Provide new xmlBuf based saving functions
* include/libxml/tree.h: adds xmlBufGetNodeContent and xmlBufNodeDump
as xmlBuf based equivalents of xmlNodeGetContent and xmlNodeDump
* tree.c: implements one new routine and converts xmlNodeBufGetContent
to use the xmlBuf equivalent. It should behave better as a result
in case of data larger than 2GB.
include/libxml/tree.h | 11 +++++++++++
tree.c | 49 ++++++++++++++++++++++++++++++++++++++++---------
2 files changed, 51 insertions(+), 9 deletions(-)
---
diff --git a/include/libxml/tree.h b/include/libxml/tree.h
index 7e821bb..8f80d8d 100644
--- a/include/libxml/tree.h
+++ b/include/libxml/tree.h
@@ -1048,9 +1048,14 @@ XMLPUBFUN void XMLCALL
int len);
XMLPUBFUN xmlChar * XMLCALL
xmlNodeGetContent (xmlNodePtr cur);
+
XMLPUBFUN int XMLCALL
xmlNodeBufGetContent (xmlBufferPtr buffer,
xmlNodePtr cur);
+XMLPUBFUN int XMLCALL
+ xmlBufGetNodeContent (xmlBufPtr buf,
+ xmlNodePtr cur);
+
XMLPUBFUN xmlChar * XMLCALL
xmlNodeGetLang (xmlNodePtr cur);
XMLPUBFUN int XMLCALL
@@ -1158,6 +1163,12 @@ XMLPUBFUN int XMLCALL
xmlSaveFormatFile (const char *filename,
xmlDocPtr cur,
int format);
+XMLPUBFUN size_t XMLCALL
+ xmlBufNodeDump (xmlBufPtr buf,
+ xmlDocPtr doc,
+ xmlNodePtr cur,
+ int level,
+ int format);
XMLPUBFUN int XMLCALL
xmlNodeDump (xmlBufferPtr buf,
xmlDocPtr doc,
diff --git a/tree.c b/tree.c
index 8baae3d..62c8e16 100644
--- a/tree.c
+++ b/tree.c
@@ -41,6 +41,8 @@
#include <libxml/debugXML.h>
#endif
+#include "buf.h"
+
int __xmlRegisterCallbacks = 0;
/************************************************************************
@@ -5246,11 +5248,39 @@ xmlNodeGetBase(xmlDocPtr doc, xmlNodePtr cur) {
int
xmlNodeBufGetContent(xmlBufferPtr buffer, xmlNodePtr cur)
{
+ xmlBufPtr buf;
+ int ret;
+
if ((cur == NULL) || (buffer == NULL)) return(-1);
+ buf = xmlBufFromBuffer(buffer);
+ ret = xmlBufGetNodeContent(buf, cur);
+ buffer = xmlBufBackToBuffer(buf);
+ if ((ret < 0) || (buffer == NULL))
+ return(-1);
+ return(0);
+}
+
+/**
+ * xmlBufGetNodeContent:
+ * @buffer: a buffer
+ * @cur: the node being read
+ *
+ * Read the value of a node @cur, this can be either the text carried
+ * directly by this node if it's a TEXT node or the aggregate string
+ * of the values carried by this node child's (TEXT and ENTITY_REF).
+ * Entity references are substituted.
+ * Fills up the buffer @buffer with this value
+ *
+ * Returns 0 in case of success and -1 in case of error.
+ */
+int
+xmlBufGetNodeContent(xmlBufPtr buf, xmlNodePtr cur)
+{
+ if ((cur == NULL) || (buf == NULL)) return(-1);
switch (cur->type) {
case XML_CDATA_SECTION_NODE:
case XML_TEXT_NODE:
- xmlBufferCat(buffer, cur->content);
+ xmlBufCat(buf, cur->content);
break;
case XML_DOCUMENT_FRAG_NODE:
case XML_ELEMENT_NODE:{
@@ -5261,10 +5291,10 @@ xmlNodeBufGetContent(xmlBufferPtr buffer, xmlNodePtr cur)
case XML_CDATA_SECTION_NODE:
case XML_TEXT_NODE:
if (tmp->content != NULL)
- xmlBufferCat(buffer, tmp->content);
+ xmlBufCat(buf, tmp->content);
break;
case XML_ENTITY_REF_NODE:
- xmlNodeBufGetContent(buffer, tmp);
+ xmlBufGetNodeContent(buf, tmp);
break;
default:
break;
@@ -5308,16 +5338,16 @@ xmlNodeBufGetContent(xmlBufferPtr buffer, xmlNodePtr cur)
while (tmp != NULL) {
if (tmp->type == XML_TEXT_NODE)
- xmlBufferCat(buffer, tmp->content);
+ xmlBufCat(buf, tmp->content);
else
- xmlNodeBufGetContent(buffer, tmp);
+ xmlBufGetNodeContent(buf, tmp);
tmp = tmp->next;
}
break;
}
case XML_COMMENT_NODE:
case XML_PI_NODE:
- xmlBufferCat(buffer, cur->content);
+ xmlBufCat(buf, cur->content);
break;
case XML_ENTITY_REF_NODE:{
xmlEntityPtr ent;
@@ -5335,7 +5365,7 @@ xmlNodeBufGetContent(xmlBufferPtr buffer, xmlNodePtr cur)
* xmlNodeGetContent() which handles all possible node types */
tmp = ent->children;
while (tmp) {
- xmlNodeBufGetContent(buffer, tmp);
+ xmlBufGetNodeContent(buf, tmp);
tmp = tmp->next;
}
break;
@@ -5357,13 +5387,13 @@ xmlNodeBufGetContent(xmlBufferPtr buffer, xmlNodePtr cur)
if ((cur->type == XML_ELEMENT_NODE) ||
(cur->type == XML_TEXT_NODE) ||
(cur->type == XML_CDATA_SECTION_NODE)) {
- xmlNodeBufGetContent(buffer, cur);
+ xmlBufGetNodeContent(buf, cur);
}
cur = cur->next;
}
break;
case XML_NAMESPACE_DECL:
- xmlBufferCat(buffer, ((xmlNsPtr) cur)->href);
+ xmlBufCat(buf, ((xmlNsPtr) cur)->href);
break;
case XML_ELEMENT_DECL:
case XML_ATTRIBUTE_DECL:
@@ -5372,6 +5402,7 @@ xmlNodeBufGetContent(xmlBufferPtr buffer, xmlNodePtr cur)
}
return(0);
}
+
/**
* xmlNodeGetContent:
* @cur: the node being read
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]