diff options
author | Benjamin Dauvergne <bdauvergne@entrouvert.com> | 2010-06-29 14:15:08 +0000 |
---|---|---|
committer | Benjamin Dauvergne <bdauvergne@entrouvert.com> | 2010-06-29 14:15:08 +0000 |
commit | 35347922850c0c3435e7ed55597aba02d219d68c (patch) | |
tree | fa20b95112cdc7d5fc4aed97b30241c4e94ab677 /bindings/java | |
parent | 2e9e814b0900dae14e291ee7708ee92b4035c019 (diff) | |
download | lasso-35347922850c0c3435e7ed55597aba02d219d68c.tar.gz lasso-35347922850c0c3435e7ed55597aba02d219d68c.tar.xz lasso-35347922850c0c3435e7ed55597aba02d219d68c.zip |
[Bindings] accept simple string in string<->xmlNode converter
Some use case ask for passing simple libxml content node (i.e just an
UTF-8 string) when a method argument or a field of the xmlNode* type.
This commit add a static method in bindings/utils.c named
lasso_string_fragment_to_xmlnode which does this transform by trying to
parse an XML document then by trying to parse a well balanced XML
fragment of only one node (if there is more than one node such as in the
string " xxx <tag/> yyy ", we free the node list and return NULL).
Diffstat (limited to 'bindings/java')
-rw-r--r-- | bindings/java/wrapper_top.c | 15 |
1 files changed, 4 insertions, 11 deletions
diff --git a/bindings/java/wrapper_top.c b/bindings/java/wrapper_top.c index 5dcb5fda..e83a2737 100644 --- a/bindings/java/wrapper_top.c +++ b/bindings/java/wrapper_top.c @@ -7,6 +7,7 @@ #include <string.h> #include "../ghashtable.h" #include "../../lasso/utils.h" +#include "../utils.c" #define LASSO_ROOT "com/entrouvert/lasso/" #define check_exception (*env)->ExceptionCheck(env) @@ -324,18 +325,10 @@ jstring_to_xml_node(JNIEnv *env, jstring jstr, xmlNode **xmlnode) { lasso_return_val_if_fail(jstring_to_local_string(env, jstr, &local_str), 0); if (local_str) { - doc = xmlReadDoc((unsigned char *)local_str, NULL, NULL, XML_PARSE_NONET); - if (!doc) { - exception(env, "could not read an xml document"); - ret = 0; - goto out; - } - node = xmlDocGetRootElement(doc); + node = lasso_string_fragment_to_xmlnode(local_str, 0); } -out: - lasso_assign_xml_node(*xmlnode, node) - if (doc) - lasso_release_doc(doc); + lasso_assign_new_xml_node(*xmlnode, node) + lasso_release_doc(doc); if (jstr && local_str) release_local_string(env, jstr, local_str); return ret; |