
Java RSS Reader ;)
By: a guest on
Dec 27th, 2012 | syntax:
Java | size: 0.82 KB | hits: 35 | expires: Never
import javax.xml.bind.*;
import javax.xml.bind.annotation.*;
@XmlRootElement(name = "rss") public class RSSReader {
@XmlElement Channel channel;
public static void main(String... args) throws Exception {
if (args.length == 0)
System.out.println("Example: java RSSReader http://www.reddit.com/r/java/.rss");
else {
RSSReader reader = JAXB.unmarshal(new java.net.URL(args[0]), RSSReader.class);
System.out.printf("%n%s%n", reader.channel.title);
for (Item i : reader.channel.items)
System.out.printf("%n== %s ==%n<%s>%n%s%n", i.title, i.link, i.description);
}
}
static class Channel {
@XmlElement String title;
@XmlElement(name = "item") java.util.List<Item> items;
}
static class Item {
@XmlElement String description;
@XmlElement String title;
@XmlElement String link;
}
}