PDA

View Full Version : QtXmlPatterns problem



momesana
4th February 2008, 20:52
Hi all. I've just started experimenting around with XQuery and the QtXmlPatterns module. I've
put together a small example application but it results in a Segfault. The test.xql script however
works just fine when processed by the patternist command or Saxon. It's also noteworthy that
changing


...
for $value in doc("test.xml")/test/entries/entry[@attr = 'y']
return $value
to


...
for $value in doc("test.xml")/test/entries/entry[@attr = 'y']
return string($value)
fixes the problem. But for now I want to play around with the nodes, not with the Atomic values they contain.

Main.cpp:


#include <QtGui>
#include <QtXmlPatterns>

int main(int argc, char* argv[])
{
QApplication app(argc, argv);
QXmlQuery query;

QFile f("test.xql");
if (!f.open(QIODevice::ReadOnly | QIODevice::Text)) {
qDebug() << "couldn't open query file.";
return 1;
}

query.setQuery(&f);
if (!query.isValid()) {
qDebug() << "query not valid.";
return 1;
}

QXmlResultItems results;
query.evaluateToResult(&results);

for (QXmlItem item = results.next(); !item.isNull(); item = results.next()) {
if (item.isAtomicValue()) {
qDebug() << item.toAtomicValue().toString();
} else
qDebug() << "encountered node";
}
return 0;
}
XQuery script (test.xql):


for $value in doc("test.xml")/test/entries/entry[@attr = 'y']
return $value
Xml File (test.xml):


<test>
<entries>
<entry attr="x">Value 1</entry>
<entry attr="y">Value 2</entry>
<entry attr="z">Value 3</entry>
</entries>
</test>

momesana
5th February 2008, 22:27
Just upgraded to the newest Snapshot and realised that the issue is gone :D.