How do I use QXmlQuery properly? (Qt XQuery/XPath)
Posted
by Steven Jackson
on Stack Overflow
See other posts from Stack Overflow
or by Steven Jackson
Published on 2010-04-21T19:22:14Z
Indexed on
2010/04/21
22:03 UTC
Read the original article
Hit count: 323
I'm using the following code to load in an XML file (actually an NZB):
QXmlQuery query;
query.bindVariable("path", QVariant(path));
query.setQuery("doc($path)/nzb/file/segments/segment/string()");
if(!query.isValid())
throw QString("Invalid query.");
QStringList segments;
if(!query.evaluateTo(&segments))
throw QString("Unable to evaluate...");
QString string;
foreach(string, segments)
qDebug() << "String: " << string;
With the following input, it works as expected:
<?xml version="1.0" encoding="iso-8859-1" ?>
<!DOCTYPE nzb PUBLIC "-//newzBin//DTD NZB 1.0//EN" "http://www.newzbin.com/DTD/nzb/nzb-1.0.dtd">
<nzb>
<file>
<groups>
<group>alt.binaries.cd.image</group>
</groups>
<segments>
<segment>[email protected]</segment>
</segments>
</file>
</nzb>
However, with the following input no results are returned. This is how the input should be formatted, with attributes:
<?xml version="1.0" encoding="iso-8859-1" ?>
<!DOCTYPE nzb PUBLIC "-//newzBin//DTD NZB 1.0//EN" "http://www.newzbin.com/DTD/nzb/nzb-1.0.dtd">
<nzb xmlns="http://www.newzbin.com/DTD/2003/nzb">
<file poster="[email protected]" date="1225385180" subject="ubuntu-8.10-desktop-i386 - ubuntu-8.10-desktop-i386.par2 (1/1)">
<groups>
<group>alt.binaries.cd.image</group>
</groups>
<segments>
<segment bytes="66196" number="1">[email protected]</segment>
<segment bytes="661967" number="1">[email protected]</segment>
</segments>
</file>
</nzb>
Please can someone tell me what I'm doing wrong?
© Stack Overflow or respective owner