开发者

RSS Parsing in QML

开发者 https://www.devze.com 2023-04-04 11:56 出处:网络
I wanna parse RSS feed with QML. the feed structure looks like <channel> <item> <title>

I wanna parse RSS feed with QML.

the feed structure looks like

<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>

my p开发者_StackOverflow中文版roblem is with the media:content tag, how can i parse the url with QML into a string ?


Can't add a comment to coyotte508's answer, so here it is instead: you might need to add namespace for the 'media' using the XmlListModel's namespaceDeclarations property. An example:

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


See http://doc.qt.nokia.com/4.7-snapshot/qml-xmllistmodel.html and http://doc.qt.nokia.com/4.7-snapshot/qml-xmlrole.html

Basically:

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()"
  }
}

And to retrieve it:

mymodel.get(0).url

If you have several channels and would like to retrieve the url for each, you can get the number of channels with mymodel.count, and access each of them with mymodel.get(i).

0

精彩评论

暂无评论...
验证码 换一张
取 消