Results 1 to 3 of 3

Thread: Can't get QXmlQuery to return results

  1. #1
    Join Date
    Aug 2006
    Posts
    90
    Thanks
    6
    Thanked 4 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Can't get QXmlQuery to return results

    Basically I have wrote a method to test XQuery in Qt 4.4.
    I can not get this thing to return any results!
    I dummied up some data in the variable "sSampleData" for testing.

    I've tried different XQueries like "doc($internalFile)/html/body/p", but they all return no results. I don't get any errors... just no results.

    Do you guys see something glaringly wrong?


    Qt Code:
    1. void QtDemo44::SearchFromString(const QString& sQuery, const QString& sData)
    2. {
    3. QString sSampleData = "<html>"
    4. " <body>"
    5. " <p id='test'>I love Jessica</p>"
    6. " <p>Something else</p>"
    7. " </body>"
    8. "</html>";
    9.  
    10. QBuffer InputDevice;
    11. InputDevice.setData(sSampleData.toUtf8());
    12. bool bOpenInput = InputDevice.open(QIODevice::ReadOnly);
    13.  
    14. if (bOpenInput == false)
    15. {
    16. QMessageBox::warning(this, "Buffer Error", "Could not open buffer");
    17. return;
    18. }
    19.  
    20. QXmlQuery xmlQuery;
    21.  
    22. QString sNewQuery = "declare variable $internalFile external;\n" + sQuery;
    23. xmlQuery.bindVariable("internalFile", &InputDevice);
    24. xmlQuery.setQuery(sNewQuery);
    25.  
    26. bool bIsValid = xmlQuery.isValid();
    27.  
    28. if (bIsValid == true)
    29. {
    30. // One way
    31. //QStringList slResults;
    32. //xmlQuery.evaluateTo(&slResults);
    33.  
    34. //if (slResults.size() > 0)
    35. //{
    36. // QMessageBox::warning(this, "Found something!", "This actually works?");
    37. //}
    38.  
    39. // Another way
    40. QString sResults;
    41. QBuffer OutputDevice;
    42. OutputDevice.setData(sResults.toUtf8());
    43. OutputDevice.open(QIODevice::ReadWrite);
    44. QXmlSerializer xmlSerializer(xmlQuery, &OutputDevice);
    45. xmlQuery.evaluateTo(&xmlSerializer);
    46.  
    47. uiDemo.txtResults->setPlainText(sResults);
    48. }
    49. else
    50. {
    51. QMessageBox::warning(this, "XQuery Error", "The query set was not valid");
    52. }
    53. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    May 2006
    Posts
    788
    Thanks
    49
    Thanked 48 Times in 46 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Can't get QXmlQuery to return results

    Have a look on example
    /4.4.0_src/examples/xmlpatterns/recipes

    QXmlFormatter return only text ??? not Domelement or node...

    QXmlQuery can bee usefull only if can return and find nodes ...

  3. #3
    Join Date
    Aug 2006
    Posts
    90
    Thanks
    6
    Thanked 4 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Can't get QXmlQuery to return results

    Thanks patrik08. It switched to the QXmlFormatter like in the example... still didn't work. Then I change from putting a QString my QBuffer to a QByteArray... and that worked. I would really think it would work with a QString... but oh well.

    Thanks a lot!

Similar Threads

  1. QSql*Model + QTreeView : make a tree
    By punkypogo in forum Qt Programming
    Replies: 18
    Last Post: 24th October 2008, 18:14
  2. Once more : QAbstractItemModel woes
    By Valheru in forum Qt Programming
    Replies: 10
    Last Post: 15th January 2008, 10:44
  3. QTableView Repaint/Refresh
    By millsks in forum Newbie
    Replies: 9
    Last Post: 10th January 2008, 17:18
  4. Qt Cryptographic Architecture
    By vermarajeev in forum Qt Programming
    Replies: 6
    Last Post: 9th February 2007, 13:15
  5. Version 4.1.3 and QTreeView
    By greencastor in forum Qt Programming
    Replies: 2
    Last Post: 13th June 2006, 10:37

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.