Cpper
C/C++高级工程师 Android高级软件工程师 IT集成工程师 音频工程师 熟悉c,c++,java,c#,py,js,asp等多种语言 程序猿
#include <Qt/QFile.h>
#include 
<Qt/QDom.h>
#include 
<iostream>

void showNodeInfo(const QDomNode& node)
{
    std::cout
<<"node name:"<<node.nodeName().toStdString()<<std::endl;
    QDomNode subnode 
= node.firstChild();
    std::cout
<<" node id:"<<subnode.nodeName().toStdString()<<std::endl;
    std::cout
<<" node id value:"<<subnode.toElement().text().toStdString()<<std::endl;
    subnode 
= subnode.nextSibling();
    std::cout
<<" node name:"<<subnode.nodeName().toStdString()<<std::endl;
    std::cout
<<" node name value:"<<subnode.toElement().text().toStdString()<<std::endl;
    subnode 
= subnode.nextSibling();
    std::cout
<<" node prefix:"<<subnode.nodeName().toStdString()<<std::endl;
    std::cout
<<" node prefix value:"<<subnode.toElement().text().toStdString()<<std::endl;
}

int main(int argc, char *argv[])
{
    QDomDocument doc;
    QFile xmlfile(
"config.xml");
    
if(!xmlfile.open(QIODevice::ReadOnly))return false;
    
if(doc.setContent(&xmlfile))
    {
        QDomElement root 
= doc.documentElement();
        QDomNode node 
= root.firstChild();
        
for(;node.isNull()!=true;node=node.nextSibling())
            showNodeInfo(node);
    }
    system(
"pause");
    
return 1;
}

基本步骤:
1.使用QFile载入文件
2.给QDomDocument设置文件内容
3.从QDomDocument获取文档根节点
4.遍历节点并作处理
posted on 2012-01-15 21:25 ccsdu2009 阅读(1312) 评论(0)  编辑 收藏 引用

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理