2011-12-23 256 views

回答

3

您可能想要使用ROME庫。這裏有一個例子:

package com.infosys.hanumant.rome; 

import java.net.URL; 
import java.util.Iterator; 

import com.sun.syndication.feed.synd.SyndEntry; 
import com.sun.syndication.feed.synd.SyndFeed; 
import com.sun.syndication.io.SyndFeedInput; 
import com.sun.syndication.io.XmlReader; 

/** 
* @author Hanumant Shikhare 
*/ 
public class Reader { 

    public static void main(String[] args) throws Exception { 

    URL url = new URL("http://example.com/feed.xml"); 
    XmlReader reader = null; 

    try { 
     reader = new XmlReader(url); 
     SyndFeed feed = new SyndFeedInput().build(reader); 
     System.out.println("Feed Title: "+ feed.getAuthor()); 

     for (Iterator i = feed.getEntries().iterator(); i.hasNext();) { 
     SyndEntry entry = (SyndEntry) i.next(); 
     System.out.println(entry.getTitle()); 
     } 
    } finally { 
     if (reader != null) 
     reader.close(); 
     } 
    } 
} 

的例子是從here複製。

+0

羅馬甚至會作出英勇的嘗試來處理無效的RSS提要。我認爲它值得學習曲線。 – Bill