<HmiRequest>
<Type>AlertPopup</Type>
<Id>123</Id>
<Order>new</Order>
<HmiContent>
<ATBev_1000_Label_NatureOfCall>eCall</ATBev_1000_Label_NatureOfCall>
</HmiContent>
</HmiRequest>
在上面的xml文件中,我想用111更新Id值“123”。 123到111。 我可以更新标签名称,但值如何更改?
答案 0 :(得分:0)
试试这个
QDomDocument doc;
doc.setContent(QString("<HmiRequest> <Type>AlertPopup</Type> <Id>123</Id> <Order>new</Order> <HmiContent> <ATBev_1000_Label_NatureOfCall>eCall</ATBev_1000_Label_NatureOfCall> </HmiContent></HmiRequest>"), false);
QDomNodeList lstNodes = doc.documentElement().childNodes();
int iCount = lstNodes. count();
for (int i = 0; i < iCount; ++i)
{
if (lstNodes.at(i).nodeName() == "Id")
{
QDomElement newIdTag = doc.createElement(QString("Id"));
QDomText idVal = doc.createTextNode(QString("111"));
newIdTag.appendChild(idVal);
doc.documentElement().replaceChild(newIdTag, lstNodes.at(i));
break;
}
}
qDebug() << doc.toString(4);