xml 的修改
bool XmlStream::modiXml(constQString&fileName)
{
QFilefile(fileName);
if(!file.open(QFile::ReadOnly|QFile::Text))
{
std::cerr<<"Error:Cannotreadfile"
returnfalse;
}
QStringerrorStr;
interrorLine;
interrorColumn;
QDomDocumentdoc;
if(!doc.setContent(&file,false,&errorStr,
&errorLine,&errorColumn))
{
std::cerr<<"Error:Parseerroratline"
<<errorLine<<","
<<"column"<<errorColumn<<":"
<<qPrintable(errorStr)<<std::endl
return false;
}
file.close();
QDomElementroot=doc.documentElement();
QDomNodechild=root.firstChild();
while(!child.isNull())
{
if(child.toElement().tagName()=="name")
{
QDomElementel=child.toElement();
QDomNodeoldnode=el.firstChild();
el.firstChild().setNodeValue(xmlScenario->getScenarioName());
QDomNodenewnode=el.firstChild();
el.replaceChild(newnode,oldnode);
std::cerr<<qPrintable(el.tagName())<<std::endl;
std::cerr<<qPrintable(el.text())<<std::endl;
child=child.nextSibling();
}
else
{
child=child.nextSibling();}
}
QFilef(fileName);
if(!f.open(QFile::WriteOnly|QFile::Text))
{
std::cerr<<"Error:Cannotreadfile"
<<qPrintable(fileName)
<<":"<<qPrintable(f.errorString())
<<std::endl; return false;
}
QTextStreamout(&f);
root.save(out,4);
return true;
}
浙公网安备 33010602011771号