• 博客园logo
  • 会员
  • 周边
  • 新闻
  • 博问
  • 闪存
  • 众包
  • 赞助商
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录

cyz88

  • 博客园
  • 联系
  • 订阅
  • 管理

公告

View Post

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;
}

posted on 2012-09-28 13:51  cyz88  阅读(136)  评论(0)    收藏  举报

刷新页面返回顶部
 
博客园  ©  2004-2026
浙公网安备 33010602011771号 浙ICP备2021040463号-3