tags:

views:

152

answers:

5

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 certain tags that are of uninterest to me and not to be used by the RSS Reader? Thanks.

A: 

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.

AHungerArtist
+2  A: 

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.

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

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:

Blaise Doughan
+2  A: 

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.

limc
+1  A: 

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/

Mondain
+4  A: 

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

Kwebble
Perfect, this was very helpful! RSS up and running within Java in around 5 minutes :) Needed to download jdom (dependency) as well as Rome
Syntax