关于使用Informa RSS Library的问题

时间:2010-06-15 17:15:39

标签: java rss

我刚刚开始研究这项技术,但我发现很难理解,

我想在一个简单的RSS订阅源中使用,

并显示其内容我该怎么做?

这是我到目前为止所喜欢的

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

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

这会造成一个格式错误的网址,任何人都可以帮助我吗???

2 个答案:

答案 0 :(得分:1)

我使用过Informa,但你的问题与Informa无关。您的网址 格式不正确。 java.net.URL期望标准URL,即具有“正常”方案的URL,例如“http:”。因此,它使用方案“feed:”对URL进行barfs。尝试使用:

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

此外,如果您遇到Informa问题,请尝试使用ROME API。我不久前退出使用Informa,转而使用ROME。

答案 1 :(得分:0)

我是java的新手......但这是我尝试过的简单代码,效果很好。我没有从特定网站上阅读RSS,而是从本地目录中读取RSS。使用http://informa.sourceforge.net/

上提供的Informa API
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
  }

}
相关问题