xml文件的结构:
<?xml version='1.0' encoding='GB2312'?>
<ipconfig>
<remote id="1">
<rmt_name>remote1</rmt_name>
<ipa>127.0.0.1</ipa>
<ipb>192.168.1.199</ipb>
</remote>
<remote id="3">
<rmt_name>namechanged</rmt_name>
<ipa>ipachanged</ipa>
<ipb>ipbchanged</ipb>
</remote>
<remote id="4">
<rmt_name>remote1</rmt_name>
<ipa>127.0.0.1</ipa>
<ipb>192.168.1.199</ipb>
</remote>
<remote id="5">
<rmt_name>remote1</rmt_name>
<ipa>127.0.0.1</ipa>
<ipb>192.168.1.199</ipb>
</remote>
<remote id="6">
<rmt_name>remote1</rmt_name>
<ipa>127.0.0.1</ipa>
<ipb>192.168.1.199</ipb>
</remote>
<remote id="7">
<rmt_name>remote1</rmt_name>
<ipa>127.0.0.1</ipa>
<ipb>192.168.1.199</ipb>
</remote>
<remote id="8">
<rmt_name>remote1</rmt_name>
<ipa>127.0.0.1</ipa>
<ipb>192.168.1.199</ipb>
</remote>
</ipconfig>
通过名字获取节点集合:
QDomNodeList lists=doc.elementsByTagName(“remote”);
QDomElement ele=lists.at(1).toElement();
删除节点:
QDomElement root=doc.documentElement();
root.removeChild(lists.at(1));
设置节点的值:
QDomNodeList child=lists.at(1).childNodes();
child.at(0).toElement().firstChild().setNodeValue(“namechanged”);
child.at(1).toElement().firstChild().setNodeValue(“ipachanged”);
child.at(2).toElement().firstChild().setNodeValue(“ipbchanged”);