Reputation: 31
Qt's QXmlQuery::setQuery has a polymorphism, just like:
void QXmlQuery::setQuery(const QString &sourceCode, const QUrl &documentURI = QUrl())
However, when I pass a HTML source code to the parameter sourceCode
, and try to evaluate, I can only get an error:
Error XPST0003 in file:///, at line 1, column 2: syntax error, unexpected unknown keyword, expecting QName or NCName
Here is an example:
QString srcHTML = "<html>......</html>"; // An HTML forked from any website
QXmlQuery query;
query.setQuery(srcHTML, QUrl("/html/body/"));
QString r;
query.evaluateTo(&r);
qDebug() << r;
Then an error message shows:
Error XPST0003 in file:///html/body/, at line 1, column 2: syntax error, unexpected unknown keyword, expecting QName or NCName ""
That's strange, even though I've feeded QXmlQuery::setQuery() a valid HTML source!
Upvotes: 1
Views: 367
Reputation: 167676
Use query.setFocus(srcHTML); query.setQuery("/html/body");
. Note that the input string to setFocus needs to be well-formed XML which HTML often not is.
Upvotes: 1