QString xmlPath = CSC_APP.m_strWorkPath + "/InitInfo.xml";
QFile file(xmlPath);
if (!file.open(QFile::ReadOnly | QFile::Text))
return ;
QString errorStr;
int errorLine;
int errorColumn;
QDomDocument doc;
if (!doc.setContent(&file, false, &errorStr, &errorLine, &errorColumn))
return ;
file.close();
QDomElement root = doc.documentElement();
QString str = root.tagName();
if (root.tagName() != "Root")
return ;
QDomElement element = doc.createElement("device3");
element.setAttribute("ChildName","Content");
QDomElement el_address = doc.createElement("Content ");
el_address.setAttribute("key","equipmentname");
el_address.setAttribute("value","CSC101B");
el_address.setAttribute("name","装置名称");
//QDomText text_address = doc.createTextNode("key");
//el_address.appendChild(text_address);
element.appendChild(el_address);
QDomElement el_path = doc.createElement("path");
QDomText text_path = doc.createTextNode("aa");
el_path.appendChild(text_path);
element.appendChild(el_path);
root.appendChild(element);
QFile f(xmlPath);
if (!f.open(QFile::WriteOnly | QFile::Text))
return ;
QTextStream out(&f);
QTextCodec * codec = QTextCodec::codecForName("GBK");
out.setCodec(codec);
QDomDocument xmlDoc;
QString strHead("version=\"1.0\" encoding=\"GB2312\"");
xmlDoc.appendChild(xmlDoc.createProcessingInstruction("xml", strHead));
out<
root.save(out, 3);
f.close();