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