隨筆-86  評(píng)論-33  文章-0  trackbacks-0
          需要的JAR
          1. Java SE 1.4以上的版本,下載地址: http://java.sun.com/

          2. 開(kāi)源軟件JDOM,下載地址:http://www.jdom.org/

          3. ROME  下載地址 http://wiki.java.net/bin/view/Javawsxml/Rome


          1.Rome
              Rome這個(gè)開(kāi)源工具來(lái)實(shí)現(xiàn)RSS閱讀器。Rome支持的格式很多,有RSS 0.90, RSS 0.91 Netscape, RSS 0.91 Userland, RSS 0.92, RSS 0.93, RSS 0.94, RSS 1.0, RSS 2.0, Atom 0.3, Atom 1.0 等等,幾乎囊括了目前所有的RSS atom版本。最新的Rome版本可以從http://wiki.java.net/bin/view/Javawsxml/Rome上得到。
            
          /*
           * Main.java
           *
           * Created on 2006年8月15日, 下午4:00
           *
           * To change this template, choose Tools | Template Manager
           * and open the template in the editor.
           
          */

          package rssdemo;

          import com.sun.syndication.feed.synd.SyndEntry;
          import com.sun.syndication.feed.synd.SyndFeed;
          import com.sun.syndication.io.FeedException;
          import com.sun.syndication.io.SyndFeedInput;
          import com.sun.syndication.io.XmlReader;
          import java.io.IOException;
          import java.net.MalformedURLException;
          import java.net.URL;
          import java.net.URLConnection;
          import java.util.List;
          import java.util.Properties;

          /**
           *
           * 
          @author Administrator
           
          */
          public class Main {
              String urlStr 
          = "http://rss.sina.com.cn/news/marquee/ddt.xml";
              
          /** Creates a new instance of Main */
              
          public Main() {
              }
              
              
          /**
               * 鏈接rss
               
          */
              
          public void rss(){   
                  
          try {
                      URL feedUrl 
          = new URL(urlStr);
                      SyndFeedInput input 
          = new SyndFeedInput();
                      SyndFeed feed 
          = input.build(new XmlReader(feedUrl));
                      
          this.show(feed);
                  } 
          catch (IllegalArgumentException ex) {
                      ex.printStackTrace();
                  } 
          catch (IOException ex) {
                      ex.printStackTrace();
                  } 
          catch (FeedException ex) {
                      ex.printStackTrace();
                  }
                  
              }
              
               
          /**
               * 通過(guò)代理鏈接rss
               
          */
              
          public void agentRss() {     
                  
          try {
                      URLConnection feedUrl 
          = new URL(urlStr).openConnection();
                      feedUrl.setRequestProperty(
          "User-Agent""Mozilla/4.0 (compatible; MSIE 5.0; Windows NT; DigExt)");
                      SyndFeedInput input 
          = new SyndFeedInput();     
                      SyndFeed feed 
          = input.build(new XmlReader(feedUrl));
                  } 
          catch (IllegalArgumentException ex) {
                      ex.printStackTrace();
                  } 
          catch (IOException ex) {
                      ex.printStackTrace();
                  } 
          catch (FeedException ex) {
                      ex.printStackTrace();
                  }
              }
              
              
          /**
               *設(shè)置HTTP代理
               
          */
              
          public void setHttpProxy(){
              Properties systemSettings 
          = System.getProperties();
              systemSettings.put(
          "http.proxyHost""192.168.40.80");
              systemSettings.put(
          "http.proxyPort""80");
              System.setProperties(systemSettings);  
              }
              
              
          /**
               *顯示信息
               
          */
              
          public void show(SyndFeed feed){
              List list 
          = feed.getEntries();
                
          for (int i=0; i< list.size(); i++) {
                  SyndEntry entry 
          = (SyndEntry)list.get(i);
                  System.out.println(entry.getTitle()
          +" | "+entry.getAuthor()+" | "+entry.getLink());
                } 
              }
              
          /**
               * 
          @param args the command line arguments
               
          */
              
          public static void main(String[] args) {
                  Main m 
          = new Main();
                  m.setHttpProxy();
                  m.rss();
              }    
          }
          posted on 2006-08-15 17:46 Derek.Guo 閱讀(2013) 評(píng)論(0)  編輯  收藏 所屬分類: Java
          <2006年8月>
          303112345
          6789101112
          13141516171819
          20212223242526
          272829303112
          3456789

          留言簿(7)

          隨筆分類(83)

          文章分類

          技術(shù)網(wǎng)站

          積分與排名

          • 積分 - 189112
          • 排名 - 306

          最新隨筆

          最新評(píng)論

          閱讀排行榜

          MSN:envoydada@hotmail.com QQ:34935442
          主站蜘蛛池模板: 睢宁县| 南皮县| 客服| 苍梧县| 扶绥县| 大悟县| 裕民县| 乌鲁木齐市| 辽中县| 吉木乃县| 竹山县| 河北省| 昆山市| 郎溪县| 屯昌县| 桂东县| 错那县| 柳州市| 贵州省| 宝兴县| 驻马店市| 玉林市| 三原县| 涪陵区| 上虞市| 游戏| 阳城县| 清涧县| 黄冈市| 河津市| 宾阳县| 周宁县| 五家渠市| 纳雍县| 兰溪市| 自贡市| 唐海县| 资兴市| 陕西省| 家居| 安图县|