1 #ifndef XML2JSON_HPP_INCLUDED
2 #define XML2JSON_HPP_INCLUDED
47 const char * runPtr = input;
51 while (*runPtr !=
'\0')
60 else if (isalpha(*runPtr))
74 jn.SetString(name, allocator);
75 jsvalue_target = jsvalue.FindMember(name)->value;
76 if(jsvalue_target.IsArray())
78 jsvalue_target.PushBack(jsvalue_chd, allocator);
79 jsvalue.RemoveMember(name);
80 jsvalue.AddMember(jn, jsvalue_target, allocator);
86 jsvalue_array.SetArray();
87 jsvalue_array.PushBack(jsvalue_target, allocator);
88 jsvalue_array.PushBack(jsvalue_chd, allocator);
89 jsvalue.RemoveMember(name);
90 jsvalue.AddMember(jn, jsvalue_array, allocator);
104 jv.SetString(myattr->value(), allocator);
111 jv.SetString(myattr->value(), allocator);
117 double value = std::strtod(myattr->value(),
nullptr);
122 long int value = std::strtol(myattr->value(),
nullptr, 0);
127 jsvalue.AddMember(jn, jv, allocator);
137 jsvalue_chd.SetObject();
144 jsvalue.SetString(xmlnode->value(), allocator);
155 jv.SetString(xmlnode->
first_node()->value(), allocator);
156 jsvalue.AddMember(jn, jv, allocator);
193 jsvalue.SetDouble(
value);
197 long int value = std::strtol(xmlnode->
first_node()->value(),
nullptr, 0);
198 jsvalue.SetInt(
value);
208 std::map<std::string, int> name_count;
211 std::string current_name;
212 const char *name_ptr = NULL;
217 name_count[current_name]++;
219 name_ptr = jv.GetString();
223 current_name = xmlnode_chd->name();
224 name_count[current_name]++;
225 name_ptr = xmlnode_chd->name();
228 if(name_count[current_name] > 1 && name_ptr)
232 jn.SetString(name_ptr, allocator);
233 jsvalue.AddMember(jn, jsvalue_chd, allocator);
240 std::cerr <<
"err data!!" << std::endl;
248 xml_doc->
parse<0> (
const_cast<char *
>(xml_str));
256 for(xmlnode_chd = xml_doc->first_node(); xmlnode_chd; xmlnode_chd = xmlnode_chd->
next_sibling())
259 jsvalue_chd.SetObject();
267 rapidjson::Writer<rapidjson::StringBuffer> writer(buffer);
268 js_doc.Accept(writer);
270 return buffer.GetString();