我使用以下代码加载一个XML文件(实际上是一个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;通过以下输入,它可以按预期工作:
<?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>waWdnZFHevdBeZTUnZ2dnUVZ8uOdnZ2d@giganews.com</segment>
</segments>
</file>
</nzb>但是,使用以下输入不会返回任何结果。下面是输入的格式,带有属性:
<?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="test@test.test" 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">waWdnZFHevdBeZTUnZ2dnUVZ8uOdnZ2d@giganews.com</segment>
<segment bytes="661967" number="1">waWdfhrgfnZFHevdBeZTUnZ2dnUVZ8uOdnZ2d@giganews.com</segment>
</segments>
</file>
</nzb>有人能告诉我我哪里做错了吗?
发布于 2010-04-22 05:59:20
我发现这是因为我需要提供一个默认的名称空间,这需要几个小时才能弄清楚……
查询现在是:
declare default element namespace "http://www.newzbin.com/DTD/2003/nzb";
declare variable $path external;
doc($path)/nzb/file/segments/segment/string()发布于 2013-02-14 17:49:21
也许在查询中使用名称空间通配符?
doc($path)//*:file/*:segments/*:segment/string()https://stackoverflow.com/questions/2685920
复制相似问题