Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct


    Qt World Summit: Early-Bird Tickets

    QXMLQuery problems

    General and Desktop
    1
    1
    1623
    Loading More Posts
    • 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
      jc-denton last edited by

      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 Reply Quote 0
      • First post
        Last post