我有一个 XML 文档,其中包含一个已被注释掉的元素。如何在此示例应用程序中跳过该项目?
#include <QtGui>
#include <QtXml>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QPlainTextEdit editor;
QString xml = "<?xml version=\"1.0\" encoding=\"utf-8\"?>"
"<list>"
"<item id=\"1\" />"
"<item id=\"2\" />"
"<!-- <item id=\"3\" /> -->"
"<item id=\"4\" />"
"</list>";
QDomDocument doc;
doc.setContent(xml.toAscii());
QDomElement list = doc.documentElement();
QDomNodeList items = list.childNodes();
for(int x=0; x< items.count(); x++)
{
QDomElement element = items.at(x).toElement();
if(1)
{
editor.appendPlainText(QString::number(x)+": "+element.attribute("id"));
}
}
editor.show();
return app.exec();
}