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

读取测试

相关推荐
spencer_tseng18 小时前
org.xml.sax.SAXParseException: cvc-complex-type.3.2.2 sql-query result-type
xml
派大鑫wink21 小时前
【Day48】MyBatis 注解开发:替代 XML 映射文件
xml·java·mybatis
sunnyday04262 天前
Spring Boot 日志配置详解:log4j2.xml 的完整配置指南
xml·spring boot·log4j
熊出没2 天前
关于MyBatis Mapper 接口与 XML 映射机制的分析
xml·microsoft·mybatis
她说..3 天前
FIND_IN_SET()方法
xml·java·spring boot
北辰当尹3 天前
xml基础
android·xml
qqqahhh7 天前
xml文件的动态化配置,导入
xml·spring·springboot
吴声子夜歌7 天前
Maven——pom.xml详解
xml·java·maven
iSee8578 天前
struts2 XML外部实体注入漏洞复现(CVE-2025-68493)
xml·安全·struts2
爱吃土豆的马铃薯ㅤㅤㅤㅤㅤㅤㅤㅤㅤ9 天前
mapper.xml中的大于等于、小于等于
xml