【发布时间】:2020-08-06 13:38:03
【问题描述】:
我有一个 xml 文件,只想复制一些特定的节点:
来自(示例):
<1>
<2>
</2>
</1>
到:
<1>
<2>
</2>
<2>
</2>
</1>
我尝试了以下方法:
for(int i = 0; i < xmlRoot.childNodes().count(); i++) {
if(xmlRoot.childNodes().at(i).isElement()){
if(xmlRoot.childNodes().at(i).toElement().attribute("id") == "teamSection"){ //find goal element
teamNode = xmlRoot.childNodes().at(i).cloneNode(); //copy element
if(xmlRoot.childNodes().at(i).insertAfter(teamNode, xmlRoot.childNodes().at(i)).isNull()){
qDebug() << "not worked";
}
else{
qDebug() << "worked";
}
break;
}
}
}
但我认为我误解了 refChiled - 因为我的解决方案只是返回 null。 (https://doc.qt.io/qt-5/qdomnode.html - insertAfter)。如何复制一个简单的节点?
【问题讨论】: