PDA

View Full Version : Can't get QXmlQuery to return results



bpetty
13th May 2008, 07:51
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?




void QtDemo44::SearchFromString(const QString& sQuery, const QString& sData)
{
QString sSampleData = "<html>"
" <body>"
" <p id='test'>I love Jessica</p>"
" <p>Something else</p>"
" </body>"
"</html>";

QBuffer InputDevice;
InputDevice.setData(sSampleData.toUtf8());
bool bOpenInput = InputDevice.open(QIODevice::ReadOnly);

if (bOpenInput == false)
{
QMessageBox::warning(this, "Buffer Error", "Could not open buffer");
return;
}

QXmlQuery xmlQuery;

QString sNewQuery = "declare variable $internalFile external;\n" + sQuery;
xmlQuery.bindVariable("internalFile", &InputDevice);
xmlQuery.setQuery(sNewQuery);

bool bIsValid = xmlQuery.isValid();

if (bIsValid == true)
{
// One way
//QStringList slResults;
//xmlQuery.evaluateTo(&slResults);

//if (slResults.size() > 0)
//{
// QMessageBox::warning(this, "Found something!", "This actually works?");
//}

// Another way
QString sResults;
QBuffer OutputDevice;
OutputDevice.setData(sResults.toUtf8());
OutputDevice.open(QIODevice::ReadWrite);
QXmlSerializer xmlSerializer(xmlQuery, &OutputDevice);
xmlQuery.evaluateTo(&xmlSerializer);

uiDemo.txtResults->setPlainText(sResults);
}
else
{
QMessageBox::warning(this, "XQuery Error", "The query set was not valid");
}
}

patrik08
13th May 2008, 08:44
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 ...

bpetty
13th May 2008, 14:27
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!