您的位置:首页 > 编程语言 > Qt开发

qt中xml的一些补充知识点

2017-08-29 10:34 225 查看
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”);
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  qt xml