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
toCode:
... for $value in doc("test.xml")/test/entries/entry[@attr = 'y'] return $value
fixes the problem. But for now I want to play around with the nodes, not with the Atomic values they contain.Code:
... for $value in doc("test.xml")/test/entries/entry[@attr = 'y'] return string($value)
Main.cpp:
XQuery script (test.xql):Code:
#include <QtGui> #include <QtXmlPatterns> int main(int argc, char* argv[]) { QXmlQuery query; 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; }
Xml File (test.xml):Code:
for $value in doc("test.xml")/test/entries/entry[@attr = 'y'] return $value
Code:
<test> <entries> <entry attr="x">Value 1</entry> <entry attr="y">Value 2</entry> <entry attr="z">Value 3</entry> </entries> </test>