Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
QXmlQuery and XPath expression
redlars last edited by
How can I use QXmlQuery to execute an XPath expression?
Here is some test code that compiles but does not work;
int main(int argc, char *argv)
// Test code
QXmlQuery query(QXmlQuery::XPath20); query.setFocus(&file); query.setQuery("//Book"); bool validQuery = query.isValid(); qDebug() << "QXmlQuery::isValid: " << validQuery; QStringList results; query.evaluateTo(&results); int count = results.count(); qDebug() << "QStringList::Count: " << count; return 0;
Books.xml looks like this;
<?xml version="1.0" encoding="utf-8"?>
According to QXmlQuery the query is valid but the result is always 0. Have tried various combinations of the query but nothing seems to work.
The XPath expression works when testing it here: http://www.bit-101.com/xpath/
Appreciate some help.