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

读取测试

相关推荐
largecode20 小时前
企业名称能在来电显示吗?号码显示公司名服务打通多终端展示
android·xml·ios·iphone·xcode·webview·phonegap
只可远观3 天前
Android XML命令式和Jetpack Compose声明式UI
android·xml
鹏晨互联3 天前
《深入理解 Compose 中的 matchParentSize 与 fillMaxSize —— 从 XML 到 Compose 的对比解析》
xml
小短腿的代码世界3 天前
Qt SVG渲染管线全解析:从XML解析到像素绘制的完整架构设计与性能优化实战
xml·qt·性能优化
HMS工业网络4 天前
技术干货:EtherCAT设备ESI(XML)文件中的CompleteAccess关键字有什么作用
xml·运维·服务器
鹏晨互联5 天前
【Compose vs XML:边框内外间距的实现对比】
android·xml
鹏晨互联6 天前
Jetpack Compose vs XML:fillMaxSize、fillMaxHeight、fillMaxWidth 全面对比
android·xml
如果'\'真能转义说7 天前
OOXML 文档格式剖析:哈希、ZIP结构与识别
xml·算法·c#·哈希算法
ZC跨境爬虫8 天前
跟着 MDN 学 HTML day_34:(深入XML 中的 CDATASection 接口)
xml·前端·html·html5·媒体