diff options
author | Benjamin Dauvergne <bdauvergne@entrouvert.com> | 2012-09-28 22:58:10 +0200 |
---|---|---|
committer | Benjamin Dauvergne <bdauvergne@entrouvert.com> | 2012-09-28 22:58:24 +0200 |
commit | bd0f935a2450b5779a01e9e5053267ec4cac94d6 (patch) | |
tree | c717cd2c11a4f0c272a38eae778cc54039f4d4d2 /bindings/java | |
parent | e94015f8bcc168c9882348d2e8c5a5138ea56676 (diff) | |
download | lasso-bd0f935a2450b5779a01e9e5053267ec4cac94d6.tar.gz lasso-bd0f935a2450b5779a01e9e5053267ec4cac94d6.tar.xz lasso-bd0f935a2450b5779a01e9e5053267ec4cac94d6.zip |
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.
Diffstat (limited to 'bindings/java')
-rw-r--r-- | bindings/java/wrapper_top.c | 40 |
1 files changed, 22 insertions, 18 deletions
diff --git a/bindings/java/wrapper_top.c b/bindings/java/wrapper_top.c index dfdec346..54bdeef6 100644 --- a/bindings/java/wrapper_top.c +++ b/bindings/java/wrapper_top.c @@ -282,35 +282,39 @@ jstring_to_string(JNIEnv *env, jstring jstr, char **str) { /* xmlNode handling */ +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 int xml_node_to_jstring(JNIEnv *env, xmlNode *xmlnode, jstring *jstr) { - xmlOutputBufferPtr buf = NULL; + xmlBuffer *buffer; g_error_if_fail(env); if (! xmlnode) { *jstr = NULL; return 1; } - - buf = xmlAllocOutputBuffer(NULL); - if (buf) { - int ret = 1; - xmlNodeDumpOutput(buf, NULL, xmlnode, 0, 1, NULL); - xmlOutputBufferFlush(buf); - xmlChar *str = NULL; - if (buf->conv == NULL) { - str = buf->buffer->content; - } else { - str = buf->conv->content; - } - ret = string_to_jstring(env, (char*)str, jstr); - xmlOutputBufferClose(buf); - return ret; - } else { + buffer = xmlnode_to_xmlbuffer(xmlnode); + if (! buffer) { exception(env, "could not alloc an xml output buffer"); return 0; } - return 1; + return string_to_jstring(env, (char*)xmlBufferContent(buffer), jstr); } /** Convert a java string to an xml node. Return 0 if it failed with an exception |