sailfish

How to get RSS flux in QML

For this example, i using the QtQuick 1.1, but normally, you shouldn’t have problem if you use the newer version of QtQuick.

For this example, i getting the RSS from http://vianavigo.com/fr/actualites-trafic/rss-vianavigo-vos-transports-en-commun-en-ile-de-france-optile-ratp-sncf/?type=102

XmlListModel{
id: xmlModel
source: "http://vianavigo.com/fr/actualites-trafic/rss-vianavigo-vos-transports-en-commun-en-ile-de-france-optile-ratp-sncf/?type=102"
query: "/rss/channel/item
namespaceDeclarations: "declare namespace content=\"http://purl.org/rss/1.0/modules/content/\";"   //For getting content:encoded !!
XmlRole { name: "pubDate"; query: "pubDate/string()" }
XmlRole { name: "titre"; query: "title/string()" }
XmlRole { name: "description"; query: "description/string()" }
XmlRole { name: "detail"; query: "content:encoded/string()" }            //You should declare the namespace for getting this parameters
}

And now your xmlModel is ready you can use

ListView{
id: listView
model: xmlModel
}

For getting this example :

media:thumbnail url="<a href="http://farm5.static.flickr.com/4048/4362801851_b80289ca0e_s.jpg">http://farm5.static.flickr.com/4048/4362801851_b80289ca0e_s.jpg</a>"height="75" width="75"

 

XmlRole { name: "thumbnail"; query: 'media:thumbnail/@url/string()' }