Skip to content

Instantly share code, notes, and snippets.

@zester
Created September 13, 2011 19:39
Show Gist options
  • Save zester/1214859 to your computer and use it in GitHub Desktop.
Save zester/1214859 to your computer and use it in GitHub Desktop.
QtXml QDom Example
#include <QtXml>
#include <iostream>
int main(int argc, char *argv[])
{
QDomDocument doc("mydoc");
QFile file("shared-mime-info.xml");
if(!file.open(QFile::ReadOnly | QFile::Text)) return 1;
if(!doc.setContent(&file)) {
file.close();
return 1;
}
file.close();
QDomElement docElem = doc.documentElement();
QDomNode n = docElem.firstChild();
while(!n.isNull()) {
QDomElement mimetype = n.toElement();
if(!mimetype.isNull()) {
QString summery = mimetype.firstChildElement("summery").text();
std::cout << "summery: " << qPrintable(summery) << std::endl;
QString description = mimetype.firstChildElement("description").text();
std::cout << "description: " << qPrintable(description) << std::endl;
QString icon = mimetype.firstChildElement("icon").attribute("value");
std::cout << "icon: " << qPrintable(icon) << std::endl;
QString pattern = mimetype.firstChildElement("pattern").attribute("value");
std::cout << "pattern: " << qPrintable(pattern) << std::endl;
QString application = mimetype.firstChildElement("application").attribute("value");
std::cout << "application: " << qPrintable(application) << std::endl;
std::cout << std::endl;
}
n = n.nextSibling();
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment