Getting an RSS feed and putting it into a cach

Android doesn’t like redirects with network.request.   If you can find the real address that might help.  You can tether your device to your computer and run adb logcat to see the log from device.

http://docs.coronalabs.com/guide/basics/debugging/index.html

Rob

Where can I find the Business Sample?

https://github.com/coronalabs/business-app-sample

I migrated this into my app (thanks!) and I was able to read certain feeds:

http://news.lvhn.org/rss/

But, when I tried some other feeds, it doesn’t seem to see the stories.  I’m not an expert on RSS by any stretch, so I’m not sure what the difference is.  Here are the one it won’t read:

http://www.ems1.com/ems-rss-feeds/news.xml

Other than the extension, I don’t know what the difference is.

I plugged in and it worked.  You  have to make sure you’re using the RSS parser and not the Atom parser.   The feed.lua file in the Business Sample App defaults to an Atom feed.

Rob

EDIT:  Sorry grabbed the wrong feed. let me look a bit more.

Rob

Okay, the reason the 2nd one doesn’t work is because the feed is invalid… See:

http://validator.w3.org/feed/check.cgi?url=http%3A%2F%2Fwww.ems1.com%2Fems-rss-feeds%2Fnews.xml

What’s actually breaking things is that <language> tag at the top.  The RSS parser expects the <channel> tag to be the first thing there… I’ve got a fix to get around this issue.

You will need to edit rss.lua and change this block of code:

&nbsp;&nbsp;&nbsp; if myFeed == nil then return nil end &nbsp;&nbsp;&nbsp; local items = myFeed.child[1].child &nbsp;&nbsp;&nbsp; local i &nbsp;&nbsp;&nbsp; print("Number of items: " .. #items)

to

&nbsp;&nbsp;&nbsp; if myFeed == nil then return nil end &nbsp;&nbsp;&nbsp; local items &nbsp;&nbsp;&nbsp; for i = 1, #myFeed.child do &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if myFeed.child[i].name == "channel" then &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; items = myFeed.child[i].child &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; break; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; end &nbsp;&nbsp;&nbsp; end &nbsp;&nbsp;&nbsp; print("Number of items: " .. #items)

It now searched through the whole feed to look for the channel tag instead of assuming that <channel> would be the first tag in the file.  Of course, this helps harden the code which is a good thing, but still at the end of the day, the feed is invalid.  That service should consider making sure their feeds pass validation.

Now there are other things that fail validation.  I don’t know what impact that will have on parsing things further into the feed. 

I may have found another bug in the XML parser and I need to do more testing before I can produce a patch for it.  This will get you going for now.

Rob

Thanks!  I can contact them about their feed… but who knows whether it will change.

Let me know if you patch the bug.

The bug in xml.lua seems to be that if an entry doesn’t end with a newline character, it looses the last character for string inside of CDATA tags.  I just have to do more testing on more feeds to make sure the fix isn’t breaking something else.  I’ve never noticed this before because most of the time there is a newline marker at the end.

I was able to get the new feed read in… BUT… only in the simulator.  No matter what I try… when I build for Android… making sure I can get to the site… and the rss feed itself through chrome… I get a feed not available message and then it hangs.

Are you getting errors in your console log?

No errors… that I see… just the normal output about number of stories, and the output for each row.  That’s the simulator, where it works.  Obviously, there’s no console on the app - where it ISN’T working.

I’ve confirmed that I can get to the website on my phone, so I’m not sure what’s going on.

I did notice that the link:

http://www.ems1.com/ems-rss-feeds/news.xml

actually gives me a redirect message about downloading their app - but I assume that’s because of the browser version it detects when I try to view it.  Could that have anything to do with it?

Android doesn’t like redirects with network.request.   If you can find the real address that might help.  You can tether your device to your computer and run adb logcat to see the log from device.

http://docs.coronalabs.com/guide/basics/debugging/index.html

Rob