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

读取测试

相关推荐
利刃大大2 天前
【Mybatis】Mybatis入门 && 基础操作 && XML配置文件开发 && 多表查询 && 注入问题 && 数据库连接池
xml·数据库·mybatis
墨痕诉清风4 天前
java漏洞集合工具(Struts2、Fastjson、Weblogic(xml)、Shiro、Log4j、Jboss、SpringCloud)
xml·java·struts·安全·web安全·spring cloud·log4j
Lbwnb丶4 天前
failure: repodata/repomd.xml from base: [Errno 256] No more mirrors to try.
xml
拾忆,想起4 天前
设计模式三大分类完全解析:构建高质量软件的基石
xml·微服务·设计模式·性能优化·服务发现
前网易架构师-高司机4 天前
汽车充电插口识别数据集,可识别快充,慢充插口,支持yolo,coco json,pascal voc xml格式的标注数据集
xml·yolo·汽车·快充·充电·m慢充·插口
武藤一雄4 天前
彻底吃透.NET中序列化反序列化
xml·微软·c#·json·.net·.netcore
spencer_tseng4 天前
org.eclipse.wst.common.project.facet.core.xml could not be read.
xml·java·eclipse
小鸡吃米…4 天前
Python - XML 处理
xml·开发语言·python·开源
老歌老听老掉牙4 天前
Vericut 5轴机床MCH文件解析与构建指南
xml·python·vericut
ii_best5 天前
「安卓开发辅助工具按键精灵」xml全分辨率插件jsd插件脚本教程
android·xml·开发语言·编辑器·安卓