Titanium Community Questions & Answer Archive

We felt that 6+ years of knowledge should not die so this is the Titanium Community Questions & Answer Archive

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

— asked September 26th 2010 by John Howell
  • down
  • drill
  • feed
  • rss
  • xml_rss.js
0 Comments

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… :\

    — answered September 28th 2010 by Simon Kok
    permalink
    4 Comments
    • Thanks for that! Works great for article titles. Is the missing image tag the reason it wasn't working? Would like to have that too. Any idea on how I would add one to an RSS feed that comes from a Joomla CMS? PS - Total Recall wasn't bad - for a Schwarzenegger film anyway. A remake is on the way too…

      — commented September 28th 2010 by John Howell
    • I didn't see an image field in your XML, so I modified the KitchenSink example to not display the image. But I think the important thing was this line:

      var doctitle = doc.evaluate("//channel/title/text()").item(0).nodeValue;
      

      I'm not familar with Joomla CMS - but there's probably a way to add a custom field - which may trigger the XML to include that custom field.
      Good luck!

      — commented September 30th 2010 by Simon Kok
    • Simon, I have tried and tried and tried to get the above code to work, with the sort of feed url in the above example, (i.e www.example.com/feed) AND images, I just cant do it!! I have been trying to understand your comment regarding ~var doctitle = doc.evaluate("//channel/title/text()").item(0).nodeValue;~ but I just dont see how it, in your code above, differs from the original KS example code.

      I would really appreciate some clarification on this matter. Can I get the above code to work with a feed that contains post with and without images? And how would that look?

      Thank you so much for already elaborating on tis issue!

      Best regards,

      — commented April 13th 2011 by Max Finnsjö
    • 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

      — commented December 3rd 2011 by bill Almen
  • 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

    — answered December 3rd 2011 by bill Almen
    permalink
    0 Comments
The ownership of individual contributions to this community generated content is retained by the authors of their contributions.
All trademarks remain the property of the respective owner.