用QML-XmlListModel解析XML

用QML-XmlListModel解析XML,xml,qml,Xml,Qml,我一直在用XmlListModel解析xml文件时遇到问题,这是xml文件 <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.x

我一直在用XmlListModel解析xml文件时遇到问题,这是xml文件

<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
    <SOAP-ENV:Body>
        <ns1:searchResponse xmlns:ns1="http://tempuri.org">
             <return xsi:type="SOAP-ENC:Array" SOAP-ENC:arrayType="unnamed_struct_use_soapval[10]">
                <item>
                    <title xsi:type="xsd:string">Es Messi deportista del año en Israel</title>
                    <excerpt xsi:type="xsd:string">El grupo editorial.............</excerpt>
                    <img xsi:type="xsd:string">http://www.noticiasmvs.com/media/fotos/9edd0407a7bd0a47df3ece7869678c4a.jpg</img>
                    <url xsi:type="xsd:string">http://www.noticiasmvs.com/xmlapp/article.php?noticia_id=52872</url>
                    <pubdate xsi:type="xsd:string">miércoles 28 de diciembre de 2011, 03:01:54</pubdate>
                 </item>
                 <item>
                    <title xsi:type="xsd:string">Primera ronda de los playoffs NBA</title>
                    <excerpt xsi:type="xsd:string">Resultados de los partidos ya disputados y programa de los que restan por jugar de la primera ronda de los playoffs de la NBA</excerpt>
                    <img xsi:type="xsd:string">     http://www.noticiasmvs.com/media/fotos/7b9e23b87817132e9a1771cad7de819d.jpg</img>
                    <url xsi:type="xsd:string">http://www.noticiasmvs.com/xmlapp/article.php?noticia_id=4982</url>
                    <pubdate xsi:type="xsd:string">viernes 30 de abril de 2010, 01:27:17</pubdate>
                </item>
             </return>
         </ns1:searchResponse>
     </SOAP-ENV:Body>
 </SOAP-ENV:Envelope>
}


最后,它返回status ready,但模型中没有元素,我做错了什么???

您的查询字符串不正确:您必须写入包含其名称空间的元素名称。XPath表达式应该如下所示:

/SOAP-ENV:Envelope/SOAP-ENV:Body/ns1:searchResponse/return/item
要在查询中使用名称空间,必须在XQuery中声明它们。这里有一个例子:

导入QtQuick 1.1
长方形{
XmlListModel{
id:searchParser
来源:“data.xml”//包含xml内容
查询:“/SOAP-ENV:Envelope/SOAP-ENV:Body/ns1:searchResponse/return/item”
namespaceDeclarations:“声明命名空间SOAP-ENV=”http://schemas.xmlsoap.org/soap/envelope/';
声明名称空间ns1=http://tempuri.org';"
XmlRole{name:“title”;查询:“title/string()”}
XmlRole{name:“摘录”;查询:“摘录/string()”}
XmlRole{name:“img”;查询:“img/string()”}
XmlRole{name:“url”;查询:“url/string()”}
XmlRole{name:“pubdate”;查询:“pubdate/string()”}
onCountChanged:console.log(“计数:”,计数)
}
}
/SOAP-ENV:Envelope/SOAP-ENV:Body/ns1:searchResponse/return/item