Source code below for reading RSS from news site (ex. bbc). I get this code from rgagnon. ROME library can be downloader here (JDOM, ROME)
import com.sun.syndication.feed.synd.*;
import com.sun.syndication.feed.synd.SyndFeed;
import com.sun.syndication.io.SyndFeedInput;
import com.sun.syndication.io.XmlReader;
import java.net.URL;
import java.util.List;
import java.util.Iterator;
public class ParseRSSFeedUsingRome {
public static void main(String args[]) throws Exception {
//String feed = "http://www.voanews.com/templates/Articles.rss?sectionPath=/indonesian/news";
String feed = "http://www.bbc.co.uk/indonesia/index.xml";
URL feedUrl = new URL(feed);
SyndFeedInput input = new SyndFeedInput();
SyndFeed sf = input.build(new XmlReader(feedUrl));
List entries = sf.getEntries();
Iterator it = entries.iterator();
while (it.hasNext()) {
SyndEntry entry = (SyndEntry)it.next();
System.out.println(entry.getTitle());
System.out.println(entry.getLink());
SyndContent description = entry.getDescription();
System.out.println(description.getValue());
System.out.println();
}
}
}
No comments:
Post a Comment