国产一级a片免费看高清,亚洲熟女中文字幕在线视频,黄三级高清在线播放,免费黄色视频在线看

打開APP
userphoto
未登錄

開通VIP,暢享免費(fèi)電子書等14項(xiàng)超值服

開通VIP
基于java的RSS
什么是RSS?
  RSS是一種網(wǎng)頁內(nèi)容聯(lián)合格式(web content sydication format)。
  它的名字是Really Simple Syndication的縮寫。
  RSS是XML的一種。所有的RSS文檔都遵循XML 1.0規(guī)范,該規(guī)范發(fā)布在W3C網(wǎng)站上。
  RSS是站點(diǎn)用來和其他站點(diǎn)之間共享內(nèi)容的一種簡易方式(也叫聚合內(nèi)容),通常被用于新聞和其他按順序排列的網(wǎng)站,例如Blog。一段項(xiàng)目的介紹可能包含新聞的全部介紹,Blog post等等。
Java代碼

/**   
     * 根據(jù)鏈接地址得到數(shù)據(jù)   
     * @param url RSS形式的xml文件   
     * @throws IllegalArgumentException   
     * @throws FeedException   
     */     
    public void parseXml(URL url) throws IllegalArgumentException, FeedException {         
     
        try {         
            SyndFeedInput input = new SyndFeedInput();         
            SyndFeed feed = null;         
            URLConnection conn;         
            conn = url.openConnection();         
            String content_encoding = conn.getHeaderField("Content-Encoding");         
                  
            if (content_encoding != null && content_encoding.contains("gzip")) {         
                System.out.println("conent encoding is gzip");         
                GZIPInputStream gzin = new GZIPInputStream(conn         
                        .getInputStream());         
                feed = input.build(new XmlReader(gzin));         
            } else {         
                feed = input.build(new XmlReader(conn.getInputStream()));         
            }         
                  
            List entries = feed.getEntries();//得到所有的標(biāo)題<title></title>      
            for(int i=0; i < entries.size(); i++) {      
                SyndEntry entry = (SyndEntry)entries.get(i);      
                System.out.println(entry.getTitle());      
            }      
            System.out.println("feed size:" + feed.getEntries().size());         
              
        } catch (IOException e) {         
            e.printStackTrace();         
        }         
         
    }      
public void createXml() throws Exception {      
        /* 根據(jù)Channel源碼提供的英文,Channel對象有兩個構(gòu)造器,一個默認(rèn)的無參構(gòu)造器用于clone對象,一個是有參的   
        * 我們自己指定的必須使用有參數(shù)的(因?yàn)槲覀冃枰S可證),指構(gòu)造方法必須要創(chuàng)建一個type(版本),這個type不能隨便寫,必須要以rss_開頭的版本號   
        * Licensed under the Apache License, Version 2.0 (the "License");   
        * 因?yàn)楫?dāng)前版本是2.0,所以就是rss_2.0,必須是rss_2.0否則會拋異常,該源碼中寫的已經(jīng)很明白。   
        */     
       Channel channel = new Channel("rss_2.0");      
       channel.setTitle("channel標(biāo)題");//網(wǎng)站標(biāo)題      
        channel.setDescription("channel的描述");//網(wǎng)站描述      
        channel.setLink("www.shlll.net");//網(wǎng)站主頁鏈接      
        channel.setEncoding("utf-8");//RSS文件編碼      
        channel.setLanguage("zh-cn");//RSS使用的語言      
        channel.setTtl(5);//time to live的簡寫,在刷新前當(dāng)前RSS在緩存中可以保存多長時間(分鐘)      
        channel.setCopyright("版權(quán)聲明");//版權(quán)聲明      
        channel.setPubDate(new Date());//RSS發(fā)布時間      
        List<Item> items = new ArrayList<Item>();//這個list對應(yīng)rss中的item列表               
        Item item = new Item();//新建Item對象,對應(yīng)rss中的<item></item>      
       item.setAuthor("hxliu");//對應(yīng)<item>中的<author></author>      
       item.setTitle("新聞標(biāo)題");//對應(yīng)<item>中的<title></title>      
       item.setGuid(new Guid());//GUID=Globally Unique Identifier 為當(dāng)前新聞指定一個全球唯一標(biāo)示,這個不是必須的      
        item.setPubDate(new Date());//這個<item>對應(yīng)的發(fā)布時間      
        item.setComments("注釋");//代表<item>節(jié)點(diǎn)中的<comments></comments>      
        //新建一個Description,它是Item的描述部分      
        Description description = new Description();      
       description.setValue("新聞主題");//<description>中的內(nèi)容      
        item.setDescription(description);//添加到item節(jié)點(diǎn)中      
        items.add(item);//代表一個段落<item></item>,      
        channel.setItems(items);      
        //用WireFeedOutput對象輸出rss文本      
        WireFeedOutput out = new WireFeedOutput();      
        try {      
            System.out.println(out.outputString(channel));      
        } catch (IllegalArgumentException e) {      
            e.printStackTrace();      
        } catch (FeedException e) {      
            e.printStackTrace();      
        }      
     
}   

/**  
     * 根據(jù)鏈接地址得到數(shù)據(jù)  
     * @param url RSS形式的xml文件  
     * @throws IllegalArgumentException  
     * @throws FeedException  
     */  
    public void parseXml(URL url) throws IllegalArgumentException, FeedException {      
  
        try {      
            SyndFeedInput input = new SyndFeedInput();      
            SyndFeed feed = null;      
            URLConnection conn;      
            conn = url.openConnection();      
            String content_encoding = conn.getHeaderField("Content-Encoding");      
               
            if (content_encoding != null && content_encoding.contains("gzip")) {      
                System.out.println("conent encoding is gzip");      
                GZIPInputStream gzin = new GZIPInputStream(conn      
                        .getInputStream());      
                feed = input.build(new XmlReader(gzin));      
            } else {      
                feed = input.build(new XmlReader(conn.getInputStream()));      
            }      
               
            List entries = feed.getEntries();//得到所有的標(biāo)題<title></title>   
            for(int i=0; i < entries.size(); i++) {   
                SyndEntry entry = (SyndEntry)entries.get(i);   
                System.out.println(entry.getTitle());   
            }   
            System.out.println("feed size:" + feed.getEntries().size());      
           
        } catch (IOException e) {      
            e.printStackTrace();      
        }      
      
    }   
public void createXml() throws Exception {   
        /* 根據(jù)Channel源碼提供的英文,Channel對象有兩個構(gòu)造器,一個默認(rèn)的無參構(gòu)造器用于clone對象,一個是有參的  
        * 我們自己指定的必須使用有參數(shù)的(因?yàn)槲覀冃枰S可證),指構(gòu)造方法必須要創(chuàng)建一個type(版本),這個type不能隨便寫,必須要以rss_開頭的版本號  

        * Licensed under the Apache License, Version 2.0 (the "License");  
        * 因?yàn)楫?dāng)前版本是2.0,所以就是rss_2.0,必須是rss_2.0否則會拋異常,該源碼中寫的已經(jīng)很明白。  
        */  
       Channel channel = new Channel("rss_2.0");   
       channel.setTitle("channel標(biāo)題");//網(wǎng)站標(biāo)題   
        channel.setDescription("channel的描述");//網(wǎng)站描述   
        channel.setLink("www.shlll.net");//網(wǎng)站主頁鏈接   
        channel.setEncoding("utf-8");//RSS文件編碼   
        channel.setLanguage("zh-cn");//RSS使用的語言   
        channel.setTtl(5);//time to live的簡寫,在刷新前當(dāng)前RSS在緩存中可以保存多長時間(分鐘)   
        channel.setCopyright("版權(quán)聲明");//版權(quán)聲明   
        channel.setPubDate(new Date());//RSS發(fā)布時間   
        List<Item> items = new ArrayList<Item>();//這個list對應(yīng)rss中的item列表            
        Item item = new Item();//新建Item對象,對應(yīng)rss中的<item></item>   
       item.setAuthor("hxliu");//對應(yīng)<item>中的<author></author>   
       item.setTitle("新聞標(biāo)題");//對應(yīng)<item>中的<title></title>   
       item.setGuid(new Guid());//GUID=Globally Unique Identifier 為當(dāng)前新聞指定一個全球唯一標(biāo)示,這個不是必須的   
        item.setPubDate(new Date());//這個<item>對應(yīng)的發(fā)布時間   
        item.setComments("注釋");//代表<item>節(jié)點(diǎn)中的<comments></comments>   
        //新建一個Description,它是Item的描述部分   
        Description description = new Description();   
       description.setValue("新聞主題");//<description>中的內(nèi)容   
        item.setDescription(description);//添加到item節(jié)點(diǎn)中   
        items.add(item);//代表一個段落<item></item>,   
        channel.setItems(items);   
        //用WireFeedOutput對象輸出rss文本   
        WireFeedOutput out = new WireFeedOutput();   
        try {   
            System.out.println(out.outputString(channel));   
        } catch (IllegalArgumentException e) {   
            e.printStackTrace();   
        } catch (FeedException e) {   
            e.printStackTrace();   
        }   
  
}  


本站僅提供存儲服務(wù),所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點(diǎn)擊舉報(bào)。
打開APP,閱讀全文并永久保存 查看更多類似文章
猜你喜歡
類似文章
RSS 2.0 Specification參考手冊
Java 中如何實(shí)現(xiàn)RSS 2.0?
php完美的rss 生成類
java中使用JDBC連接數(shù)據(jù)庫的步驟
RSS原理和實(shí)現(xiàn)
實(shí)現(xiàn)讀取RSS 2.0的Javascript類
更多類似文章 >>
生活服務(wù)
分享 收藏 導(dǎo)長圖 關(guān)注 下載文章
綁定賬號成功
后續(xù)可登錄賬號暢享VIP特權(quán)!
如果VIP功能使用有故障,
可點(diǎn)擊這里聯(lián)系客服!

聯(lián)系客服