From bd0f935a2450b5779a01e9e5053267ec4cac94d6 Mon Sep 17 00:00:00 2001 From: Benjamin Dauvergne Date: Fri, 28 Sep 2012 22:58:10 +0200 Subject: Rewrite all xmlNode serialization code to be compatible with libxml 2.9.0 Libxml stopped exposing the internal of the xmlOutputBuffer structure; it was replace by proper use of the API and of the xmlBuffer structure. There could be regression for older version of libxml as some functions appeared in recent version of libxml; but the reference API document does not give any introduction date for functions so it's hard to be sure. --- bindings/python/wrapper_top.c | 34 +++++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 11 deletions(-) (limited to 'bindings/python') diff --git a/bindings/python/wrapper_top.c b/bindings/python/wrapper_top.c index c80bf1d6..a9312b7c 100644 --- a/bindings/python/wrapper_top.c +++ b/bindings/python/wrapper_top.c @@ -103,28 +103,40 @@ get_dict_from_hashtable_of_strings(GHashTable *value) return proxy; } +static xmlBuffer* +xmlnode_to_xmlbuffer(xmlNode *node) +{ + xmlOutputBufferPtr output_buffer; + xmlBuffer *buffer; + + if (! node) + return NULL; + + buffer = xmlBufferCreate(); + output_buffer = xmlOutputBufferCreateBuffer(buffer, NULL); + xmlNodeDumpOutput(output_buffer, NULL, node, 0, 0, NULL); + xmlOutputBufferClose(output_buffer); + xmlBufferAdd(buffer, BAD_CAST "", 1); + + return buffer; +} + static PyObject* get_pystring_from_xml_node(xmlNode *xmlnode) { - xmlOutputBufferPtr buf; PyObject *pystring = NULL; + xmlBuffer *buffer; if (xmlnode == NULL) { return NULL; } + buffer = xmlnode_to_xmlbuffer(xmlnode); - buf = xmlAllocOutputBuffer(NULL); - if (buf == NULL) { + if (buffer == NULL) { pystring = NULL; } else { - xmlNodeDumpOutput(buf, NULL, xmlnode, 0, 1, NULL); - xmlOutputBufferFlush(buf); - if (buf->conv == NULL) { - pystring = PyString_FromString((char*)buf->buffer->content); - } else { - pystring = PyString_FromString((char*)buf->conv->content); - } - xmlOutputBufferClose(buf); + pystring = PyString_FromString((char*)xmlBufferContent(buffer)); + xmlBufferFree(buffer); } return pystring; -- cgit