Qt 删除节点
QFilefile(path);
if(!file.open(QFile::ReadOnly|QFile::Text))
{
std::cerr<<"Error:Cannotreadfile"
<<qPrintable(path)
<<":"<<qPrintable(file.errorString())
<<std::endl;
}
QStringerrorStr;
interrorLine;
interrorColumn;
QDomDocumentdoc;
if(!doc.setContent(&file,false,&errorStr,&errorLine,
&errorColumn))
{
std::cerr<<"Error:Parseerroratline"
<<errorLine<<","
<<"column"<<errorColumn<<":"
<<qPrintable(errorStr)<<std::endl;
}
file.close();
QDomElementroot=doc.documentElement();
QDomNodechild=root.firstChild();
while(!child.isNull())
{
if(child.toElement().tagName()=="xxxx_cfg")
{
QDomElementel=child.toElement();
QDomNodenodebChild=el.firstChild();
while(!nodebChild.isNull())
{
if(nodebChild.toElement().tagName()=="xxx_name")
{
if(nodebChild.toElement().text()==entityName)
{
root.removeChild(child);
break;
}
nodebChild=nodebChild.nextSibling();
}
else
{
nodebChild=nodebChild.nextSibling();
}
}
child=child.nextSibling();
}
else
{
child=child.nextSibling();
}
}
QFilef(path);
if(!f.open(QFile::WriteOnly|QFile::Text))
{
std::cerr<<"Error:Cannotreadfile"
<<qPrintable(path)
<<":"<<qPrintable(f.errorString())
<<std::endl;
}
QTextStreamout(&f);
root.save(out,4);
}
浙公网安备 33010602011771号