Skip to content
Snippets Groups Projects
Commit 1e318e18 authored by Arun Muthusamy's avatar Arun Muthusamy
Browse files

fix xml_to_json

parent d6d27bd6
No related branches found
No related tags found
No related merge requests found
......@@ -102,10 +102,10 @@ leave:
return NULL;
}
void xml_to_json(xmlNode *anode, struct json_object *jobj)
void xml_to_json(xmlNode *anode, json_object *jobj)
{
xmlNodePtr cur_node = NULL;
struct json_object *cur_jstr = NULL;
json_object *cur_jstr = NULL;
for (cur_node = anode; cur_node; cur_node = cur_node->next) {
debug_print("child address: %p\n", cur_node);
......@@ -115,10 +115,7 @@ void xml_to_json(xmlNode *anode, struct json_object *jobj)
if (cur_node->type == XML_ELEMENT_NODE) {
if (xmlChildElementCount(cur_node) == 0) {
cur_jstr = json_object_new_string((char *)xmlNodeGetContent(cur_node));
debug_print("xmlNodeGet name: %sn", (char *)cur_node->name);
debug_print("xmlNodeGetContent: %sn", (char *)xmlNodeGetContent(cur_node));
debug_print("xmlNodeGet name: %s\n", (char *)cur_node->name);
json_object_object_add(jobj, (char *)cur_node->name, cur_jstr);
}
}
......@@ -130,13 +127,14 @@ void xml_to_json(xmlNode *anode, struct json_object *jobj)
//free memory...
struct json_object *xml_to_json_converter(struct write_result *result)
{
struct json_object *jobj;
json_object *jobj;
xmlDocPtr doc_ptr = NULL;
xmlNode *origin_node = NULL;
doc_ptr = xmlParseMemory(result->data, result->pos);
if (!doc_ptr)
goto fail_doc_ptr;
debug_print("data from xml: %s\n", result->data);
origin_node = xmlDocGetRootElement(doc_ptr);
if (!origin_node)
......@@ -145,12 +143,10 @@ struct json_object *xml_to_json_converter(struct write_result *result)
jobj = json_object_new_object();
xml_to_json(origin_node, jobj);
debug_print("The json object created: %s\n", json_object_to_json_string(jobj));
debug_print("Json object from xml: %s\n", json_object_to_json_string(jobj));
if (doc_ptr)
xmlFreeDoc(doc_ptr);
if (origin_node)
free (origin_node);
return jobj;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment