summaryrefslogtreecommitdiff
path: root/xmlIO.c
diff options
context:
space:
mode:
authorDaniel Veillard <veillard@src.gnome.org>2005-11-09 08:56:26 +0000
committerDaniel Veillard <veillard@src.gnome.org>2005-11-09 08:56:26 +0000
commit9a00fd2991433a6ce04075c91b3ac6b976bdd806 (patch)
tree9e9238983fcd65f6fce849109639488a030fab36 /xmlIO.c
parent69dea3a0c01e8a952b1d2f07ab0a3aa450f0cdfe (diff)
downloadlibxml2-9a00fd2991433a6ce04075c91b3ac6b976bdd806.tar.gz
applied patch from Geert Jansen to implement the save function to a
* xmlsave.c xmlIO.c include/libxml/xmlIO.h include/libxml/xmlsave.h: applied patch from Geert Jansen to implement the save function to a xmlBuffer, and a bit of cleanup. Daniel
Diffstat (limited to 'xmlIO.c')
-rw-r--r--xmlIO.c62
1 files changed, 62 insertions, 0 deletions
diff --git a/xmlIO.c b/xmlIO.c
index 1dffa279..9e302aee 100644
--- a/xmlIO.c
+++ b/xmlIO.c
@@ -862,6 +862,41 @@ xmlFileFlush (void * context) {
return(ret);
}
+#ifdef LIBXML_OUTPUT_ENABLED
+/**
+ * xmlBufferWrite:
+ * @context: the xmlBuffer
+ * @buffer: the data to write
+ * @len: number of bytes to write
+ *
+ * Write @len bytes from @buffer to the xml buffer
+ *
+ * Returns the number of bytes written
+ */
+static int
+xmlBufferWrite (void * context, const char * buffer, int len) {
+ int ret;
+
+ ret = xmlBufferAdd((xmlBufferPtr) context, (const xmlChar *) buffer, len);
+ if (ret != 0)
+ return(-1);
+ return(len);
+}
+
+/**
+ * xmlBufferClose:
+ * @context: the xmlBuffer
+ *
+ * Close a buffer
+ *
+ * Returns 0 or -1 in case of error
+ */
+static int
+xmlBufferClose (void * context) {
+ return(0);
+}
+#endif
+
#ifdef HAVE_ZLIB_H
/************************************************************************
* *
@@ -2438,6 +2473,33 @@ xmlOutputBufferCreateFile(FILE *file, xmlCharEncodingHandlerPtr encoder) {
return(ret);
}
+
+/**
+ * xmlOutputBufferCreateBuffer:
+ * @buffer: a xmlBufferPtr
+ * @encoder: the encoding converter or NULL
+ *
+ * Create a buffered output for the progressive saving to a xmlBuffer
+ *
+ * Returns the new parser output or NULL
+ */
+xmlOutputBufferPtr
+xmlOutputBufferCreateBuffer(xmlBufferPtr buffer,
+ xmlCharEncodingHandlerPtr encoder) {
+ xmlOutputBufferPtr ret;
+
+ if (buffer == NULL) return(NULL);
+
+ ret = xmlAllocOutputBuffer(encoder);
+ if (ret != NULL) {
+ ret->context = buffer;
+ ret->writecallback = xmlBufferWrite;
+ ret->closecallback = xmlBufferClose;
+ }
+
+ return(ret);
+}
+
#endif /* LIBXML_OUTPUT_ENABLED */
/**