Qt修改xml文件

<taskpackage styleId="styles/2dc70235-e48b-4e11-b074-3c3f773ae1f3" id="3333" type="normal">
    <playvideo isFlash="false">
        <group times="5618" filename="groupList" playTimes="15" startTime="00:00:00">
            <item filename="COM.mp4" filesize="1.92GB" href="resource/daab3.mp4" flv="resource/aab3.mp4"/>
        </group>
    </playvideo>
    <text>欢迎</text>
</taskpackage>

修改id的值。

 

    QFile file("we.xml");
    QDomDocument doc;
 
 
    if(!file.open(QIODevice::ReadOnly))
    {
        qDebug()<<"xxx";
    }
    if(!doc.setContent(&file))
    {
        file.close();
        qDebug()<<"ttttt";
    }
    file.close();
 
 
 
 
    QDomNode old_node = doc.firstChild();
 
 
    qDebug()<<doc.firstChild().toElement().attribute("id");
 
 
    doc.firstChild().toElement().setAttribute("id", "3333");
    qDebug()<<doc.firstChild().toElement().attribute("id")<<"   "<<doc.firstChild().toElement().attribute("startTime");
    QDomNode new_node = doc.firstChild();
    doc.replaceChild(new_node, old_node);
 
 
    QFile afile("we.xml");
    afile.open(QIODevice::WriteOnly|QIODevice::Truncate);
    QTextStream out(&afile);
    doc.save(out,4);
    afile.close();

 

转载于:https://www.cnblogs.com/zhangxuan/p/5726366.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值