我正在尝试使用 Qt4.8 解析以下内容。
QString l_dynamicResult("<?xml version=\"1.0\"?>\
<u:BrowseResponse xmlns:u=\"urn:schemas-upnp-org:service:ContentDirectory:1\">\
<Result><DIDL-Lite xmlns="urn:schemas-upnp-org:metadata-1-0/DIDL-Lite/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:upnp="urn:schemas-upnp-org:metadata-1-0/upnp/" xmlns:sec="http://www.sec.co.kr/" xmlns:dlna="urn:schemas-dlna-org:metadata-1-0/"><container id="0/1" parentID="0" restricted="1"><dc:title>Fichiers</dc:title><upnp:class>object.container.storageFolder</upnp:class></container><container id="0/0" parentID="0" restricted="1"><dc:title>TV</dc:title><upnp:class>object.container.storageFolder</upnp:class></container><container id="0/5" parentID="0" restricted="1"><dc:title>Flux RSS</dc:title><upnp:class>object.container.storageFolder</upnp:class></container></DIDL-Lite></Result>\
<NumberReturned>3</NumberReturned>\
<TotalMatches>3</TotalMatches>\
<UpdateID>0</UpdateID>\
</u:BrowseResponse>");
我可以使用以下代码显示内容:
QByteArray l_array;
QBuffer l_buffer(&l_array);
l_buffer.setData(l_dynamicResult.toUtf8());
l_buffer.open(QIODevice::ReadOnly);
l_info = "declare namespace xs='http://www.w3.org/2001/XMLSchema';\
declare namespace fn='http://www.w3.org/2005/xpath-functions';\
declare namespace dc='http://purl.org/dc/elements/1.1';\
let $result := fn:doc($xmlString)//Result/fn:string() \
return ($result ) ";
QStringList l_cdsContent;
l_q.bindVariable("xmlString", &l_buffer);
l_q.setQuery(l_info);
l_res = l_q.evaluateTo(&l_cdsContent);
Log("query res=")<<(l_res ?"Ok":"error");
qDebug()<<"l_cdsContent="<<l_cdsContent;
输出是:
l_cdsContent=<DIDL-Lite xmlns="urn:schemas-upnp-org:metadata-1-0/DIDL-Lite/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:upnp="urn:schemas-upnp-org:metadata-1-0/upnp/" xmlns:sec="http://www.sec.co.kr/" xmlns:dlna="urn:schemas-dlna-org:metadata-1-0/"><container id="0/1" parentID="0" restricted="1"><dc:title>Fichiers</dc:title><upnp:class>object.container.storageFolder</upnp:class></container><container id="0/0" parentID="0" restricted="1"><dc:title>TV</dc:title><upnp:class>object.container.storageFolder</upnp:class></container><container id="0/5" parentID="0" restricted="1"><dc:title>Flux RSS</dc:title><upnp:class>object.container.storageFolder</upnp:class></container></DIDL-Lite>
要打印,我尝试使用:
let $result := fn:doc($xmlString)//Result \
let $title := $result//dc:title/fn:string() \
return ($title )
但结果是空的。
目前,解决方法是将其$result
传递给另一个 QBuffer 以应用相同的过程。
我错过了什么明显的东西吗?