QString str = QCoreApplication::applicationDirPath();
str = str + "/set.xml";if(str.isEmpty())return;QFile file(str);if( !file.open(QFile::ReadOnly | QFile::Text)){
qDebug() << QObject::tr("error::ParserXML->OpenXmlFile->file.open->%s\n") << str;return ;}
QDomDocument document;if( !document.setContent(&file)){
qDebug() << QObject::tr("error::ParserXML->OpenXmlFile->doc.setContent\n") << str;file.close();return;}
qDebug() << document.toString();QDomElement root = document.documentElement();for(int i = 0; i < root.childNodes().count(); i++){
QDomElement login = root.childNodes().at(i).toElement();qDebug() <<login.attribute("TcpluginMain");}
file.close();
运行结果:
"<?xml version='1.0' encoding='utf-8'?>\n<Message>start
\n\t<ModelOne appImage=\"app.png\" TcpluginMain=\"
MainPlugin\" description=\"主页\"/>\n <ModelOne appImage=\"app.png\" TcpluginMain=\"FavoritePlugin\"
description=\"最热\"/>\n <ModelOne appImage=\"app.png\" TcpluginMain=\"HistoryPlugin\" description=\"历史\"/>
\n</Message>\n"
""
"MainPlugin"
"FavoritePlugin"
"HistoryPlugin"
Qt提供的另一种XML解析方式QXmlStreamReader,相比QDomComment较快。
非Qt解析XML工具中:比QDomComment快。
XML解析之QDomDocument
最新推荐文章于 2024-07-08 17:59:44 发布