qt 删除xml某个标签下所有子标签

 

代码如下:

1     QDomNodeList listFlowChart= doc.elementsByTagName("device");
2     QDomElement flowChart = listFlowChart.at(0).toElement();
3     QDomNodeList listAllNodes = flowChart.childNodes();
4     while (listAllNodes.size() > 0) {
5                         flowChart.removeChild(listAllNodes.at(0));
6     }

listFlowChart 是xml中所有device标签的集合,取其中第一个,删除其下所有子标签。最好检测一下listFlowChart是否为空。

 

不能用for循环来移除标签。因为从listAllNode中每移除一个标签,listAllNode.size()都会减一。

posted @ 2019-08-21 17:32  阳光下的小土豆  阅读(718)  评论(0编辑  收藏  举报