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/python | |
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/python')
-rw-r--r-- | bindings/python/wrapper_top.c | 15 |
1 files changed, 4 insertions, 11 deletions
diff --git a/bindings/python/wrapper_top.c b/bindings/python/wrapper_top.c index 76d9da95..7879bb13 100644 --- a/bindings/python/wrapper_top.c +++ b/bindings/python/wrapper_top.c @@ -5,6 +5,7 @@ #include "../ghashtable.h" #include "../../lasso/debug.h" #include "../../lasso/utils.h" +#include "../utils.c" #if PY_VERSION_HEX < 0x02050000 && !defined(PY_SSIZE_T_MIN) typedef int Py_ssize_t; @@ -323,18 +324,10 @@ failure: static xmlNode* get_xml_node_from_pystring(PyObject *string) { - xmlDoc *doc; - xmlNode *node; - - doc = xmlReadDoc((xmlChar*)PyString_AsString(string), NULL, NULL, XML_PARSE_NONET); - node = xmlDocGetRootElement(doc); - if (node != NULL) { - node = xmlCopyNode(node, 1); - } - lasso_release_doc(doc); - - return node; + return lasso_string_fragment_to_xmlnode(PyString_AsString(string), + PyString_Size(string)); } + /** Return a tuple containing the string contained in a_list */ static PyObject * get_list_of_strings(const GList *a_list) { |