Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

Java RSS Reader ;)

By: a guest on Dec 27th, 2012  |  syntax: Java  |  size: 0.82 KB  |  views: 35  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. import javax.xml.bind.*;
  2. import javax.xml.bind.annotation.*;
  3. @XmlRootElement(name = "rss") public class RSSReader {
  4.         @XmlElement Channel channel;
  5.         public static void main(String... args) throws Exception {
  6.                 if (args.length == 0)
  7.                         System.out.println("Example: java RSSReader http://www.reddit.com/r/java/.rss");
  8.                 else {
  9.                         RSSReader reader = JAXB.unmarshal(new java.net.URL(args[0]), RSSReader.class);
  10.                         System.out.printf("%n%s%n", reader.channel.title);
  11.                         for (Item i : reader.channel.items)
  12.                                 System.out.printf("%n== %s ==%n<%s>%n%s%n", i.title, i.link, i.description);
  13.                 }
  14.         }
  15.         static class Channel {
  16.                 @XmlElement String title;
  17.                 @XmlElement(name = "item") java.util.List<Item> items;
  18.         }
  19.         static class Item {
  20.                 @XmlElement String description;
  21.                 @XmlElement String title;
  22.                 @XmlElement String link;
  23.         }
  24. }
clone this paste RAW Paste Data