• <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文件中的內(nèi)容
            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;
                }
            }

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

            //此處開始處理attribs字符串列表中的內(nèi)容
            for (int i = 0; i < attribs.count(); i++) {
                QString attribNumber 
            = QString::number(i+1); // 內(nèi)容的序號: 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); 
            // 屬性結(jié)束
            }

            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++ 領(lǐng)域扛鼎之作,榮耀先生傾情翻譯,名著名譯)</attrib>
                        
            <attrib number="02">價格:55元</attrib>
                        
            <attrib number="03">作者:(美)David Abrahams;Aleksey Gurtovoy</attrib>
                        
            <attrib number="04">出版社:機械工業(yè)出版社</attrib>
                        
            <attrib number="05">出版日期:2010-01-01</attrib>
                    
            </book>
            </archive>
            posted on 2011-11-14 10:22 再生的雄鷹 閱讀(9213) 評論(1)  編輯 收藏 引用

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

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

            常用鏈接

            留言簿(1)

            隨筆檔案

            文章分類

            文章檔案

            搜索

            •  

            最新評論

            閱讀排行榜

            評論排行榜

            久久精品国产亚洲AV无码麻豆| 欧美精品一区二区久久| 久久亚洲AV成人无码电影| 日本强好片久久久久久AAA| 9久久9久久精品| 久久久久这里只有精品| 精品国产青草久久久久福利| 久久久精品人妻一区二区三区蜜桃| 2022年国产精品久久久久| 久久精品国产99国产精品| 精品久久久无码人妻中文字幕| 久久精品国产精品青草app| 久久精品中文字幕有码| 久久精品国产亚洲AV无码偷窥| 国产伊人久久| 久久国产精品99精品国产987| 精品国产乱码久久久久软件| 久久se精品一区二区| 麻豆一区二区99久久久久| 久久久精品国产Sm最大网站| 久久综合给久久狠狠97色| 蜜桃麻豆www久久国产精品| 久久精品九九亚洲精品天堂| 亚洲精品乱码久久久久久久久久久久 | 久久免费的精品国产V∧| 青青久久精品国产免费看| 精品久久久久久久| 99久久精品国产免看国产一区| 亚洲欧洲久久久精品| 国内精品伊人久久久久网站| 91精品国产91久久综合| 久久久无码精品亚洲日韩按摩| 精品国产乱码久久久久软件| 武侠古典久久婷婷狼人伊人| 99久久国产综合精品成人影院| 99久久99这里只有免费费精品| 色欲久久久天天天综合网精品| 亚洲国产一成人久久精品| 无码精品久久久天天影视| 成人午夜精品无码区久久| 伊人久久精品无码av一区|