36 QDomDocument doc(
"xmlInput");
39 if (!file.open(QIODevice::ReadOnly)) {
40 QString message = QString(
"Failed to open file for XML Input: [%1]").arg(xmlFile);
46 if (!doc.setContent(&file, &errMsg, &errLine, &errCol)) {
48 QString message = QString(
"Failed to use file for XML Input: [%1]. %2 at line %3, column %4").arg(xmlFile).arg(errMsg).arg(errLine).arg(errCol);
97 if (element.hasAttributes()) {
100 json attributeSection;
101 QDomNamedNodeMap attrMap = element.attributes();
102 for (
int i=0; i < attrMap.size(); i++) {
103 QDomAttr attr = attrMap.item(i).toAttr();
104 attributeSection[
"attrib_"+attr.name().toStdString()] = attr.value().toStdString();
108 if (!element.text().isEmpty()) {
109 attributeSection[
"_text"] = element.text().toStdString();
111 newJson[element.tagName().replace(
":",
"_").toStdString()] = attributeSection;
116 if (!element.text().isEmpty()) {
117 newJson[element.tagName().replace(
":",
"_").toStdString()] = element.text().toStdString();
121 newJson[element.tagName().replace(
":",
"_").toStdString()];
149 while (!element.isNull()) {
150 QDomElement next = element.firstChildElement();
154 if (!output.contains(element.tagName().toStdString())){
155 output.update(converted);
161 if (!output[element.tagName().toStdString()].is_array()) {
163 repeatedArray.push_back(output[element.tagName().toStdString()]);
164 output[element.tagName().replace(
":",
"_").toStdString()] = repeatedArray;
166 output[element.tagName().replace(
":",
"_").toStdString()].push_back(converted[element.tagName().toStdString()]);
175 if (output.contains(element.tagName().toStdString())) {
179 if (!output[element.tagName().toStdString()].is_array()) {
181 repeatedArray.push_back(output[element.tagName().toStdString()]);
182 output[element.tagName().replace(
":",
"_").toStdString()] = repeatedArray;
184 output[element.tagName().replace(
":",
"_").toStdString()].push_back(temporaryJson);
187 if (element.hasAttributes()) {
189 QDomNamedNodeMap attrMap = element.attributes();
190 for (
int j=0; j < attrMap.size(); j++) {
191 QDomAttr attr = attrMap.item(j).toAttr();
192 tempArea[
"attrib_"+attr.name().toStdString()] = attr.value().toStdString();
196 output[element.tagName().replace(
":",
"_").toStdString()] = tempArea;
199 output[element.tagName().toStdString()] =
200 convertXmlToJson(next, output[element.tagName().replace(
":",
"_").toStdString()]);
204 element = element.nextSiblingElement();