• 使用QXmlStreamWriter创建xml


        QByteArray xmlcontents;
        QXmlStreamWriter xmlstreamwriter(&xmlcontents);
        xmlstreamwriter.setAutoFormatting(true);
        xmlstreamwriter.writeStartDocument();
        xmlstreamwriter.writeStartElement("xml");
        xmlstreamwriter.writeStartElement("round");
        xmlstreamwriter.writeAttribute("id", mRoundId);
        xmlstreamwriter.writeAttribute("tableid", mTableId);
        //player1
        xmlstreamwriter.writeStartElement("player1");
        xmlstreamwriter.writeAttribute("framescore", mPlayer1Frame);
        xmlstreamwriter.writeAttribute("points", mPlayer1Point);
        xmlstreamwriter.writeAttribute("break", mPlayer1ContinuePoint);
      xmlstreamwriter.writeCharacters("Hello World"); //添加内容 xmlstreamwriter.writeEndElement();
    //player2 xmlstreamwriter.writeStartElement("player2"); xmlstreamwriter.writeAttribute("framescore", mPlayer2Frame); xmlstreamwriter.writeAttribute("points", mPlayer2Point); xmlstreamwriter.writeAttribute("break", mPlayer2ContinuePoint); xmlstreamwriter.writeEndElement(); xmlstreamwriter.writeEndElement(); xmlstreamwriter.writeEndElement(); xmlstreamwriter.writeEndDocument();

    结果如下

    <?xml version="1.0" encoding="UTF-8"?>
    <xml>
        <round id="" tableid="1">
            <player1 framescore="" points="" break="">Hello World</player1>
            <player2 framescore="" points="" break=""/>
        </round>
    </xml>
  • 相关阅读:
    MySQL存储引擎简介
    MySQL基本架构介绍
    MySQL事务小结
    【术语解释】fat-jar理解
    学习NIO——Selector
    java 实现Map的深复制
    今天也要学一点设计模式呀——观察者模式
    今天也要学一点设计模式呀——代理模式
    java 将String字符串转换为List<Long>类型
    零拷贝
  • 原文地址:https://www.cnblogs.com/jck34/p/4040895.html
Copyright © 2020-2023  润新知