Qt xmlWriter/xmlReader

北慕城南 提交于 2019-12-06 05:49:21
Peter

Thanks for your answer!

I've found these links for generating and reading XML files using QT from Nokia:

Writing XML Files: http://developer.nokia.com/community/wiki/Generate_XML_programatically_in_Qt

Reading XML Files: http://www.developer.nokia.com/Community/Wiki/Using_QXmlStreamReader_to_parse_XML_in_Qt

This are the QT classes used, when writing and reading XML files:

http://doc.qt.nokia.com/4.7/qxmlstreamwriter.html

http://doc.qt.nokia.com/4.7/qxmlstreamreader.html

if you intend to parse small xml files the easiest way is using QDomDocument class, see example below taken from "C++ GUI Programming with Qt4, Second Edition".

QFile file(filename);
QString errorStr;
int errorLine;
int errorColumn;
QDomDocument doc;
if (!doc.setContent(&file, false, &errorStr, &errorLine,
                    &errorColumn)) {
    std::cerr << "Error: Parse error at line " << errorLine << ", "
              << "column " << errorColumn << ": "
              << qPrintable(errorStr) << std::endl;
    return false;
}
QDomElement root = doc.documentElement();
if (root.tagName() != "bookindex") {
    std::cerr << "Error: Not a bookindex file" << std::endl;
    return false;
}

However, the entire xml is kept in memory, so be careful with large xml files.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!