zoukankan      html  css  js  c++  java
  • 使用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>
  • 相关阅读:
    windows下pip安装python module失败
    设置jenkins的邮件通知功能
    jenkins 中 violation使用pylint
    pylint & jenkins
    dracut 基本介绍
    etcdctl 命令介绍
    python
    django --------------------- [必要操作]
    vim
    ssl选购
  • 原文地址:https://www.cnblogs.com/jck34/p/4040895.html
Copyright © 2011-2022 走看看