Sep 11, 2012, 03:29 PM
I'm wanting to create an app to show a few different RSS feeds and then let the user select articles from the feeds and show them in a web view. I'm using feeds from a Wordpress site. There are a few different feeds I want to use so I'm thinking of having buttons on the home screen of the app with each one linking up to a feed. Any help is appreciated.
Sep 11, 2012, 05:03 PM
Sep 11, 2012, 06:19 PM
I actually have an RSS parser I wrote for iOS about a month ago, but in the interest of having you learn I'll just point out some classes I used to build mine (if you need help while putting it together, ask of course, but show some evidence that you tried first, please.)
I made a subclass of NSOperation that conformed to NSXMLParserDelegate. The main thing it did was kick off an NSXMLParser with a URL. As the parser returned elements, it scanned them. If it found an element with the name "link" and an attribute "type" that was equal to "application/rss+xml", it would kick off another instance of itself using the attribute "href".
It would also look for elements with the names of title, description, pubDate, item, rss, or channel. It would look for both the start and end of each tag.
If it ever found characters between those tags, it would add them to an NSMutableString which it would "detag" (that's my own term now) and pass on to be handled elsewhere, and then empty the string variable.
By "detag", I mean that it would scan the string for HTML tags and remove them. Personally, I did it character by character and keeping track of how many "tags deep" my program was. It would replace tag substrings with empty strings (the reason being that I wanted to place them in UILabels. No idea if you'll need a similar detagger in your case.)
In the detag process, I also scanned for escape sequences and replaced them with the appropriate characters. To find those, I looked for instances of "&#" and then skipped to the ";". I would then parse the number in between, interpret it as a char, and replace the escape sequence with it.
Depending on how you're making this work, you might want to have a NSOperationQueue. In my app, I used it to queue up multiple search tasks. As I found feeds, I stuck them in an NSMutableArray.
I think I've described every portion of how my code for finding RSS feeds works now in some detail.
If you need to know more about the RSS tags, I suggest looking here (it is, after all, how I figured out what tags to look for):