开发者

Question on using Informa RSS Library

I Just started looking at this technology , but i am finding it hard to understand,

i want to just reed in a simple rss feed url,

and display its contents how could i do this?

this is what i lloked at so far

URL inpFile = new URL("feed://images.apple.com/main/rss/hotnews/hotnews.rss");
ChannelIF channel = FeedParser.parse开发者_StackOverflow社区(new ChannelBuilder(), inpFile);

System.out.println(channel.getDescription());

this creates a malformed url exeception, can anyone help me???


I've used Informa, but your problem has nothing to do with Informa. Your URL is malformed. java.net.URL expects a standard URL, i.e., one with a "normal" scheme like "http:". Thus, it barfs on a URL with the scheme "feed:". Try using:

URL inpFile = new URL("http://images.apple.com/main/rss/hotnews/hotnews.rss")
ChannelIF channel = FeedParser.parse(new ChannelBuilder(), inpFile);

Also, if you run into problems with Informa, try the ROME API. I quit using Informa, in favor of ROME, awhile ago.


Well i am new to java... but here is the simple code that I tried and works well. Instead of reading the RSS from a specific website, I read the RSS from local directory. Use Informa API available at http://informa.sourceforge.net/

public class Read_UpdateRSS implements de.nava.informa.utils.poller.PollerObserverIF {

  public static void main(String[] args) {

   try {

    File in = new File("/home/RSSFeed/rssfeed.xml");

    ChannelBuilder build = new ChannelBuilder();

    Channel channel = (Channel) FeedParser.parse(build,in);
    System.out.println("Description:" + channel.getDescription());
    System.out.println("Title:" + channel.getTitle());

    // Magic of polling starts here. polling is done every 10 minutes

    Poller poll = new Poller();
    PollerObserverIF observer = new Read_UpdateRSS();
    poll.addObserver(observer);
    poll.registerChannel(channel, 10 * 60 * 1000);

    for(Object x: channel.getItems()){

        Item anItem = (Item) x;
        System.out.println(anItem.getTitle() + "-");
        System.out.println(anItem.getDescription());
       }

    } //try ends
 catch(Exception e) { } 

}

 @Override
 public void channelChanged(ChannelIF arg0) {}

 @Override
 public void channelErrored(ChannelIF arg0, Exception arg1) {}

  @Override
  public void itemFound(ItemIF item, ChannelIF channel) {

  System.out.println("new item found");
  channel.addItem(item);
 }

 @Override
public void pollStarted(ChannelIF channel) {
System.out.println("Started polling with " + channel.getItems().size() + " items in  the channel");

}
  @Override
  public void pollFinished(ChannelIF channel) {
  System.out.println("Finished polling with " + channel.getItems().size() + " items in  the channel
  }

}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜