XML(可扩展标记语言)

复制代码
QDomDocument doc;
   QDomElement  ss= doc.createElement("root");//创建标签
//ss标签添加到文档对象
    doc.appendChild(ss);
    //doc.save()
    auto hero = doc.createElement("hero");
    ss.appendChild(hero);

    hero.setAttribute("id",10086);//为hero添加属性
    //属性名不能以数字开头

    //html中
    //<root>  <hero id = "10086"><abc>无极剑圣<abc></hero>  <abc></root>
//当添加孩子时就变成双标签了
    auto name = doc.createElement("abc");

    hero.appendChild(name);//hero的子标签
//html 中 <h1>增加内容<h1>
    hero.appendChild( doc.createTextNode("无极剑圣"));
   // doc.createTextNode("蛮族之王");

   QString filename  = QFileDialog::getSaveFileName(this,"保存xml");
    QFile ff(filename);
    if(!ff.open(QIODevice::WriteOnly))
    {
        QMessageBox::information(NULL,"信息提醒","打开失败");
        return;
    }

    //文本流
    QTextStream outstream(&ff);//获取文件的地址 创建文本流对象
    doc.save(outstream,4); //第二个参数缩进 4
    //默认utf-8 参数可不填

    ff.close();//记住文件得关闭

123.xml

读取测试

相关推荐
泡海椒9 小时前
JQuick-Excel JQuickRow 数据准备实战:JObjectConverter、JQuickRow.toRows 与 XML 导出链路
xml·windows·excel
泡海椒2 天前
JQuick-Excel 字段映射实战:用 MAPPING 固化 Excel 表头与业务字段契约
xml·java·开发语言·excel
执明wa15 天前
Android RecyclerView 多类型, 多种 Item
android·xml·开发语言·设计模式·android studio
wl851115 天前
SAP CPI 教程004 如何通过groovy修改XML节点属性值
xml
码匠许师傅17 天前
【C++三方组件】TinyXML2:两个文件的极简 XML 解析器
xml·c++
yuzhiboyouye18 天前
my-batisPlus什么时候用xml什么时候用mapper自带的方法,这两种写法专业一点叫什么,什么场景分别使用
xml
筝筝ba19 天前
如何跳过FFDC
xml·linux·运维·服务器·网络
yuzhiboyouye20 天前
那xml对应的sql语法,列举一下
xml·数据库·sql
筝筝ba24 天前
OpenBMC 自动化测试中的多进程陷阱:从 Execute Process 返回异常到 output.xml 损坏问题分析
xml·linux·运维·服务器·网络
spencer_tseng1 个月前
[j2cache ehcache.xml]/tmp/.ehcache-diskstore.lock (Permission denied)
xml·linux·python·ehcache·[j2cache