QML中的RSS解析



我想用QML解析RSS提要。

提要结构看起来像

<channel>
<item>
<title>
</title>
<description>
</description>
<media:content url="http://someURLHere.com/avatar/somethingHere?s=96&#38;d=identicon&#38;r=G" medium="image">
</media:content>
</item>

我的问题是与媒体:内容标签,我如何用QML解析url成字符串?

不能为coyotte508的回答添加注释,所以这里是:您可能需要使用XmlListModel的namespaceDeclarations属性为'media'添加名称空间。一个例子:

XmlListModel {
  ...
  namespaceDeclarations: "declare namespace media = 'http://put/the/path/here';"
  XmlRole { name: "url"; query: "media:content/@url/string()" }
}

参见http://doc.qt.nokia.com/4.7-snapshot/qml-xmllistmodel.html和http://doc.qt.nokia.com/4.7-snapshot/qml-xmlrole.html

基本上

:

XmlModel {
  id: mymodel
  xml: "blabblabla" /* you can also use source: to read directly from the web */
  query: "/rss/channel/item/"
  XmlRole {
    name: "url"
    query: "media:content/@url/string()"
  }
}

和检索它:

mymodel.get(0).url

如果您有几个通道,并希望检索每个通道的url,您可以使用mymodel获得通道的数量。计算并使用mymodel.get(i)访问它们。

最新更新