Quantcast
Viewing latest article 11
Browse Latest Browse All 30

ROME API to parse RSS/Atom

I'm trying to parse RSS/Atom feeds with the ROME library. I am new to Java, so I am not in tune with many of its intricacies.


  1. Does ROME automatically use its modules to handle different feeds as it comes across them, or do I have to ask it to use them? If so, any direction on this.
  2. How do I get to the correct 'source'? I was trying to use item.getSource(), but it is giving me fits. I guess I am using the wrong interface. Some direction would be much appreciated.

Here is the meat of what I have for collection my data. I noted two areas where I am having problems, both revolving around getting Source Information of the feed. And by source, I want CNN, or FoxNews, or whomever, not the Author. Judging from my reading, .getSource() is the correct method.

List<String> feedList = theFeeds.getFeeds();
List<FeedData> feedOutput = new ArrayList<FeedData>();
for (String sites : feedList ) {
  URL feedUrl = new URL(sites);
  SyndFeedInput input = new SyndFeedInput();
  SyndFeed feed = input.build(new XmlReader(feedUrl));
  List<SyndEntry> entries = feed.getEntries();
  for (SyndEntry item : entries){
    String title = item.getTitle();                 
    String link = item.getUri();
    Date date = item.getPublishedDate();
Problem here -->         **     SyndEntry source = item.getSource();
    String description;
    if (item.getDescription()== null){
      description = "";
    } else {
      description = item.getDescription().getValue();
    }
    String cleanDescription = description.replaceAll("\\<.*?>","").replaceAll("\\s+", " ");
    FeedData feedData = new FeedData(); 
    feedData.setTitle(title);
    feedData.setLink(link);
And Here -->        **      feedData.setSource(link);
    feedData.setDate(date);
    feedData.setDescription(cleanDescription);
    String preview =createPreview(cleanDescription);
    feedData.setPreview(preview);
    feedOutput.add(feedData);
    // lets print out my pieces.
    System.out.println("Title: " + title);
    System.out.println("Date: " + date);
    System.out.println("Text: " + cleanDescription);
    System.out.println("Preview: " + preview);
    System.out.println("*****");
  }
}

Viewing latest article 11
Browse Latest Browse All 30

Trending Articles