Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QXMLQuery problems
QtWS25 Last Chance

QXMLQuery problems

Scheduled Pinned Locked Moved General and Desktop
1 Posts 1 Posters 1.7k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    jc-denton
    wrote on last edited by
    #1

    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;

    query.setMessageHandler(&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;
    query.evaluateTo(&resultItems);
    QXmlItem item = resultItems.next();

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

    } else {

    qDebug() << "Invalid Query!";
    }

    std::cin.get();

    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??

    1 Reply Last reply
    0

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved