the code is liek this:
QFile fout
("Resources/file_out.xml");
QMap<QString, QString> IED_IPAdrr_Pair;
if (!doc_out.setContent(fout, true, &errorStr, &errorLine, &errorColumn)) {
QObject::tr("Parse error at line %1, " "column %2:\n%3")
.arg(errorLine)
.arg(errorColumn)
.arg(errorStr));
return;
}
const int Indent = 4;
QDomNode node
= findTag
(root ,
"RemoteAddressList");
QMap<QString, QString>::const_iterator i = IED_IPAdrr_Pair.constBegin();
while (i != IED_IPAdrr_Pair.constEnd()) {
QDomText t2
= doc_out.
createTextNode(i.
key());
QDomText t3
= doc_out.
createTextNode(i.
value());
QDomElement e1
= doc_out.
createElement("RemoteAddress");
e2.appendChild(t2);
e3.setAttribute("Type", "IPADRR");
e3.appendChild(t3);
e1.appendChild(e2);
e1.appendChild(e3);
node.appendChild(e1);
++i;
}
doc_out.save(out, Indent);
QFile fout("Resources/file_out.xml");
QDomDocument doc_out;
QMap<QString, QString> IED_IPAdrr_Pair;
if (!doc_out.setContent(fout, true, &errorStr, &errorLine, &errorColumn)) {
QMessageBox::warning(0, QObject::tr("DOM Parser"),
QObject::tr("Parse error at line %1, "
"column %2:\n%3")
.arg(errorLine)
.arg(errorColumn)
.arg(errorStr));
return;
}
const int Indent = 4;
QDomNode root = doc_out.firstChild();
QDomNode node = findTag(root , "RemoteAddressList");
QMap<QString, QString>::const_iterator i = IED_IPAdrr_Pair.constBegin();
while (i != IED_IPAdrr_Pair.constEnd()) {
QDomText t2 = doc_out.createTextNode(i.key());
QDomText t3 = doc_out.createTextNode(i.value());
QDomElement e1 = doc_out.createElement("RemoteAddress");
QDomElement e2 = doc_out.createElement("AR_Name");
e2.appendChild(t2);
QDomElement e3 = doc_out.createElement("NetAddr");
e3.setAttribute("Type", "IPADRR");
e3.appendChild(t3);
e1.appendChild(e2);
e1.appendChild(e3);
node.appendChild(e1);
++i;
}
QTextStream out(fout);
doc_out.save(out, Indent);
To copy to clipboard, switch view to plain text mode
here is the declaration of findTag():
QDomNode findTag(QDomNode &node, const QString &tag);
To copy to clipboard, switch view to plain text mode
it find the specified tag name and return with the a QDomNode
Bookmarks