QXMLQuery problems

  • I just want to run an XQuery expression on string containing XML and then get the result again as a string. However looking at the QtXmlQuery documentation it is not entirely clear to me how to use it. I tried to write a simple example to test it.

    @#include <iostream>

    #include <QtCore>
    #include <QtXML>
    #include <QtXmlPatterns>

    class MessageHandler: public QAbstractMessageHandler
    virtual void handleMessage(QtMsgType type,
    const QString &description,
    const QUrl &identifier,
    const QSourceLocation &sourceLocation)
    qDebug() << "Error: " << description << " at line " << sourceLocation.line()
    << " char " << sourceLocation.column() << ".";

    int main(int argc, char *argv[])
    QCoreApplication app(argc, argv);
    // app.exec();

    QString xmlInput = "<?xml version='1.0'?><root><data>hello</data></root>";
    QXmlQuery query;

    MessageHandler messageHandler;


    // According to the Qt docs use QVariant to bind a string here.
    query.bindVariable("inputDocument", QVariant(xmlInput));

    // Do I need to declare the variable here?
    query.setQuery("declare variable $inputDocument external; doc($inputDocument)//data");

    if(query.isValid()) {

    QXmlResultItems resultItems;
    QXmlItem item = resultItems.next();

    while(!item.isNull()) {
    QVariant value = item.toAtomicValue();
    qDebug() << "Got Result: " << value;
    item = resultItems.next();

    } else {

    qDebug() << "Invalid Query!";


    return 0;

    However I always get the following error (in German, because my VS is German):

    @Error: "<html ><body><p>Error opening c:/.../XQueryTester/Debug/<: Die Synta
    x f³r den Dateinamen, Verzeichnisnamen oder die Datentrõgerbezeichnung ist falsc
    h.</p></body></html>" at line -1 char -1 .@

    It says the syntax for file names or directory names is wrong. I have no idea why this happens, I didn't try to open any file??

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.