XML RSS Feed KitchenSink issue
I'd like to use an RSS feed to my website in my app, but can't seem to modify the Kitchen Sink XML_RSS.js example to work for my website's RSS feed:
http://sciencefictionworld.com/index.php?format=feed&type=rss
Can this type of feed be used (I've tried atom and RSS 1.0, 2.0, etc.) Is there something I'm missing? What would I need to get it working?
Additionally, the example provided opens a webview to the actual website, but I'd like to create a new window and display the title, image and text of each article with a back button once a row is touched (a drill down table) which a lot of news sites use. What would the modified code look like?
Any help /pointers on either of these two questions much appreciated. I've worked out most of the other bits in my app, but have a hit a wall with the RSS section!
Thanks
John
2 Answers
-
Hi John.
I took a look at your RSS feed using the REST Client in FireFox.
The XML looks just fine. You might want to add an image url tag in your XML.
Using the KitchenSink RSS example, try this:
// create table view data object var data = []; var xhr = Ti.Network.createHTTPClient(); xhr.open("GET","http://sciencefictionworld.com/index.php?format=feed&type=rss"); xhr.onload = function() { try { var doc = this.responseXML.documentElement; var items = doc.getElementsByTagName("item"); var x = 0; var doctitle = doc.evaluate("//channel/title/text()").item(0).nodeValue; for (var c=0;c<items.length;c++) { var item = items.item(c); var title = item.getElementsByTagName("title").item(0).text; var row = Ti.UI.createTableViewRow({height:80}); var label = Ti.UI.createLabel({ text:title, left:72, top:5, bottom:5, right:5 }); row.add(label); data[x++] = row; row.url = item.getElementsByTagName("link").item(0).text; } var tableview = Titanium.UI.createTableView({data:data}); Titanium.UI.currentWindow.add(tableview); tableview.addEventListener('click',function(e) { var w = Ti.UI.createWindow({title:doctitle}); var wb = Ti.UI.createWebView({url:e.row.url}); w.add(wb); var b = Titanium.UI.createButton({ title:'Close', style:Titanium.UI.iPhone.SystemButtonStyle.PLAIN }); w.setLeftNavButton(b); b.addEventListener('click',function() { w.close(); }); w.open({modal:true}); }); } catch(E) { alert(E); } }; xhr.send();
By the way, I think I'm the only person on this planet that has tried to watch that "Total Recall" movie 6 times.. and I keep falling asleep in it… :\
-
hi Simon, i am actually having the same problem with my project, and i can not come up with something to show up the images for rss feed. i tested the code you provided up, and i put different rss links but no images were showing next to the rss stories on the left side, just a white box, i there's a specific code for that ? i appreciate your time and help. thanks