• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            posts - 10,  comments - 2,  trackbacks - 0
            QDomDocument dom;
            QFile 
            *file = new QFile("books.xml");
            if (file->open(QIODevice::ReadOnly))
            {
                dom.setContent(file); 
            // 此處需做錯誤判斷
            }
            file
            ->close();

            // 以下代碼為解析XML文件中的內容
            QDomNodeList books = dom.elementsByTagName("book");
            for (int i = 0; i < books.count(); i++) {
                QDomNode book 
            = books.item(i);
                
            if (book.toElement().attribute("ISBN"== isbn) { // 查找ISBN匹配的屬性,isbn由用戶指定
                    QDomNodeList attribs = book.toElement().childNodes();

                    QDomNode node;
                    QString attribNumber,attribContent;
                    
            for (int j = 0; j < attribs.count(); j++) {
                        node 
            = attribs.item(j);
                        attribNumber 
            = node.toElement().attribute("number");
                        attribContent 
            = node.toElement().text();
                        
            //  在此可添加代碼對attribNumber,attribContent作出處理了.
                    }
                    
            break;
                }
            }

            // 以下代碼為寫內容進XML文件
            QStringList attribs = ""// 由用戶指定
            QDomElement bookNode = dom.createElement("book");
            carNode.setAttribute(
            "ISBN", isbn); // isbn由用戶指定

            //此處開始處理attribs字符串列表中的內容
            for (int i = 0; i < attribs.count(); i++) {
                QString attribNumber 
            = QString::number(i+1); // 內容的序號: 01 02 
                if (i < 10)
                    attribNumber.prepend(
            "0");

                QDomText textNode 
            = dom.createTextNode(attribs.at(i)); // 取出每一個字符串

                QDomElement attribNode 
            = dom.createElement("attrib");
                attribNode.setAttribute(
            "number", attribNumber);
                attribNode.appendChild(textNode);

                carNode.appendChild(attribNode); 
            // 屬性結束
            }

            QDomNodeList archive 
            = carDetails.elementsByTagName("archive");
            archive.item(
            0).appendChild(carNode);

            // 寫入XML文件中
            if (file->open(QIODevice::WriteOnly)) {
                QTextStream stream(file);
                archive.item(
            0).save(stream, 4);
                file
            ->close();
            }

            <?xml version="1.0" encoding="gb2312" ?>
            <archive>
                    
            <book ISBN="9787111267423">
                        
            <attrib number="01">書名:C++模板元編程(C++ 領域扛鼎之作,榮耀先生傾情翻譯,名著名譯)</attrib>
                        
            <attrib number="02">價格:55元</attrib>
                        
            <attrib number="03">作者:(美)David Abrahams;Aleksey Gurtovoy</attrib>
                        
            <attrib number="04">出版社:機械工業出版社</attrib>
                        
            <attrib number="05">出版日期:2010-01-01</attrib>
                    
            </book>
            </archive>
            posted on 2011-11-14 10:22 再生的雄鷹 閱讀(9213) 評論(1)  編輯 收藏 引用

            FeedBack:
            # re: [原創]Qt下XML文檔的讀、寫(DOM方式)
            2011-11-15 21:50 | ccsdu2009
            看見這個都煩
            為了解析一個xml寫這么多太費時間了
            還不如弄一個自動串行化的對象
              回復  更多評論
              

            <2011年11月>
            303112345
            6789101112
            13141516171819
            20212223242526
            27282930123
            45678910

            常用鏈接

            留言簿(1)

            隨筆檔案

            文章分類

            文章檔案

            搜索

            •  

            最新評論

            閱讀排行榜

            評論排行榜

            国产Av激情久久无码天堂| 国产精品久久新婚兰兰| 国产精品久久久亚洲| 成人综合伊人五月婷久久| 青青草国产精品久久| 无码人妻少妇久久中文字幕| 香蕉久久久久久狠狠色| 人妻丰满AV无码久久不卡 | 伊人久久免费视频| 久久久久亚洲AV综合波多野结衣 | 亚洲欧洲中文日韩久久AV乱码| 色悠久久久久久久综合网| 久久亚洲国产精品成人AV秋霞| 亚洲精品乱码久久久久久自慰| 91精品国产乱码久久久久久| 国产福利电影一区二区三区久久久久成人精品综合 | 亚洲精品久久久www| 久久精品国产清高在天天线| 久久国产三级无码一区二区| 亚洲伊人久久大香线蕉综合图片| 久久―日本道色综合久久| 奇米影视7777久久精品人人爽| 91精品国产9l久久久久| 精品多毛少妇人妻AV免费久久| 久久精品九九亚洲精品天堂| 国产精品中文久久久久久久 | 欧美麻豆久久久久久中文| 成人国内精品久久久久影院| 久久成人小视频| 久久天天躁狠狠躁夜夜2020| 国产精品美女久久久久| 久久精品国产精品亚洲精品| 亚洲国产成人久久一区WWW| 伊人热人久久中文字幕| 国产精品久久久久久| 久久亚洲AV成人无码国产| 久久WWW免费人成一看片| 一级做a爰片久久毛片毛片| 久久露脸国产精品| 热RE99久久精品国产66热| 久久本道久久综合伊人|