1

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!

3
  • Maybe, it is about the second parameter, see doc.qt.io/qt-5/qxmlquery.html#details . Check if QUrl is valid. Commented Apr 7, 2019 at 9:44
  • @sirop The example in my code comes from this: stackoverflow.com/a/18677398/10865463 Commented Apr 7, 2019 at 10:34
  • Then could you explain:query.setQuery("doc('index.html')/html/body/p[1]");? Commented Apr 7, 2019 at 10:59

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

So does it. Maybe I have to find another way to parse HTML.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.