开发者

Writing an RSS reader in Java

I'm trying to write a basic RSS reader for a class project. Our book shows an example by walking the DOM tree. Is that a decent approach for an RSS reader? Would I just ignore cert开发者_如何学Cain tags that are of uninterest to me and not to be used by the RSS Reader? Thanks.


For inspiration you can look at ROME, an open source tool for handling RSS & Atom feeds.


It's one of two common approaches, so yes. And yes, ignoring tags that are not of interest is a good way to handle it. If you don't need it, no need to take note of it. If you know in advance exactly what tags you need, you probably don't need to walk the entire DOM tree.

You could also use a SAX parser which would probably be faster and less memory intensive, though probably not necessary in this case, depending on how many results you wish to have in the feed.


Well, the beauty of RSS feed is they always come in some standard structure, even though some feeds contain non-standard fields, like Google Picasa's RSS feed. The most straightforward approach, in my opinion, is to use a tool that allows you to unmarshall the RSS XML feed into your RSS bean. This way, you don't need to write too much code, and you can pick what fields you want and ignore fields you don't want.

In my case, I use Castor to perform the unmarshalling process where I read the Google Picasa RSS feed and gather only the fields I want. Hope this helps.


Processing Atom Feeds with JAXB

You could also map your XML to objects using JAXB. You could then use these objects in your RSS reader.

  • http://bdoughan.blogspot.com/2010/09/processing-atom-feeds-with-jaxb.html

The JAXB reference implementation is included in Java SE 6, there are also other implementations such as MOXy (I'm the tech lead):

  • http://wiki.eclipse.org/EclipseLink/Examples/MOXy/GettingStarted

You only need to map the portions you are interested in.

Processing Atom Feeds with SDO

You could also use Service Data Objects (SDO) to do this:

  • http://bdoughan.blogspot.com/2010/09/processing-atom-feeds-with-sdo.html


I have both parsed and produced RSS with the JDOM library. Its been around a long time and is updated in-frequently, but my experience is that it hasn't needed updating. You may want to look into it but since its quite powerful, you may find that it offers too much functionality. http://jdom.org/

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜