<parent value="01"> <parent_1 value="Урал"> <parent_1_2 value="пункты"> <coord value="5"> <wheater value="10"> <violations value="7"> </parent_1_2> </parent_1> <parent_2 value="Крым"> <parent_2_1 value="пункты"> <coord value="7"> <wheater value="11"> <violations value="5"> </parent_2_1> <parent_2_2 value="склады"> <coord value="7"> <wheater value="12"> <violations value="8"> </parent_2_2> </parent_2></parent>
<parent value="01"> <parent_1_2 value="пункты"> <coord value="5"> <wheater value="10"> <violations value="7"> </parent_1_2> <parent_1_2 value="пункты"> <coord value="7"> <wheater value="11"> <violations value="5"> </parent_1_2> <parent_2_2 value="склады"> <coord value="7"> <wheater value="12"> <violations value="8"> </parent_2_2></parent>
<coord value="5"/><wheater value="10"/><violations value="7"/>
<?xml version="1.0" ?>
test1:: ...{QDomDocument doc("reportXML");const int Indent = 4; QDomElement parent = doc.createElement("rep_id"); QDomAttr domAttr = doc.createAttribute("value"); domAttr.setValue(curr_rep_xml); parent.setAttributeNode(domAttr); doc.appendChild(parent); parent.appendChild(makeElement(doc, "param1", "" , curr_param1)); parent.appendChild(makeElement(doc, "param2", "" , curr_param2)); parent.appendChild(makeElement(doc, "param3", "" , curr_param3)); parent.appendChild(makeElement(doc, "param4", curr_param4)); doc.appendChild(parent); QDomElement params = child_param(doc, cp1, cp2, cp3, cp4, cp5, cp6, cp7, cp8);parent.appendChild(params); QFile file("reportParam.xml"); if(file.open(QIODevice::WriteOnly)){ QDomNode xmlNode = doc.createProcessingInstruction("xml", "version=\"1.0\" encoding=\"KOI8R\""); doc.insertBefore(xmlNode, doc.firstChild()); QTextStream out(&file); doc.save(out, Indent); file.close(); }QDomElement test1::child_param(QDomDocument &domDoc, int cp1, const QString &cp2, const QString &cp3, const QString &cp4, const QString &cp5, const QString &cp6, const QString &cp7, const QString &cp8){ QDomElement child2_item = makeElement(domDoc, "fields", num); child2_item.appendChild(makeElement(domDoc, "num1", "", num1)); child2_item.appendChild(makeElement(domDoc, "num2", "", num2)); child2_item.appendChild(makeElement(domDoc, "num3", "", num3)); child2_item.appendChild(makeElement(domDoc, "num4", "", num4)); child2_item.appendChild(makeElement(domDoc, "num5", "", num5)); child2_item.appendChild(makeElement(domDoc, "num6", "", num6)); child2_item.appendChild(makeElement(domDoc, "num7", "", num7)); return child2_item;} QDomElement test1::makeElement(QDomDocument &domDoc, const QString &strName, const QString &strAttr, const QString &strText){ QDomElement domElement = domDoc.createElement(strName); if(!strAttr.isEmpty()) { QDomAttr domAttr = domDoc.createAttribute("value"); domAttr.setValue(strAttr); domElement.setAttributeNode(domAttr); } if(!strText.isEmpty()){ QDomAttr domAttr = domDoc.createAttribute("value"); domAttr.setValue(strText); domElement.setAttributeNode(domAttr); } return domElement;}
doc.appendChild(parent);parent.appendChild(makeElement(doc, "param1", "" , curr_param1));parent.appendChild(makeElement(doc, "param2", "" , curr_param2));parent.appendChild(makeElement(doc, "param3", "" , curr_param3));parent.appendChild(makeElement(doc, "param4", curr_param4));doc.appendChild(parent);