我正在尝试使用QXmlQuery
解析XML文件。但是,当我运行QXmlQuery::evaluateTo()
函数时,我得到一个空列表。
我的XML如下:
<?xml version="1.0" encoding="UTF-8"?>
<gpx>
<trk>
<trkseg>
<trkpt lat="42.45612" lon="-5.45623">
<ele>50.202291</ele>
<time>...</time>
<desc>lat.=42.45612, lon.=-5.45623, Alt.=50.202291m. Speed=12.225666m/h.</desc>
<speed>4.121307</speed>
</trkpt>
<trkpt lat="50.166598" lon="-2.811355">
<ele>47.236732</ele>
<time>...</time>
<desc>lat.=50.166598, lon.=-2.811355, Alt.=47.236732m. Speed=11.134823m/h.</desc>
<speed>2.123456</speed>
</trkpt>
</trkseg>
</trk>
</gpx>
我的代码如下:
QFile file(fileName);
if (!file.open(QFile::ReadOnly | QFile::Text)) {
qDebug() << "Error: Cannot read file " << qPrintable(fileName)
<< ": " << qPrintable(file.errorString())
<< "\n";
}
QXmlQuery q;
q.setFocus(&file);
q.setQuery("//gpx/string()");
bool valid = q.isValid();
QStringList items;
q.evaluateTo(&items);
qDebug() << items;
任何帮助都会受到赞赏。谢谢。