From 35347922850c0c3435e7ed55597aba02d219d68c Mon Sep 17 00:00:00 2001 From: Benjamin Dauvergne Date: Tue, 29 Jun 2010 14:15:08 +0000 Subject: [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 yyy ", we free the node list and return NULL). --- bindings/python/wrapper_top.c | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) (limited to 'bindings/python') 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) { -- cgit