集册 Java实例教程 用Rome阅读RSS

用Rome阅读RSS

欢马劈雪     最近更新时间:2020-01-02 10:19:05

445
使用罗马阅读RSS



import com.sun.syndication.feed.synd.SyndCategoryImpl;

import com.sun.syndication.feed.synd.SyndContentImpl;/*来 自 N o w  J a v a  .   c o m*/

import com.sun.syndication.feed.synd.SyndEntry;

import com.sun.syndication.feed.synd.SyndFeed;

import com.sun.syndication.feed.synd.SyndLinkImpl;

import com.sun.syndication.io.SyndFeedInput;

import com.sun.syndication.io.XmlReader;


import java.net.URL;

import java.util.List;


public class RomeEx2 {
/* 
 来自 
*时代Java*/

    public static void main(String[] args) {

        try {

            String urlString = "http://feeds.reuters.com/reuters/topNews";

            URL feedUrl = new URL(urlString);


            SyndFeedInput input = new SyndFeedInput();

            SyndFeed feed = input.build(new XmlReader(feedUrl));


            System.out.println("Feed Title: " + feed.getTitle());

            //Get the entry items...

            for (SyndEntry entry : (List<SyndEntry>) feed.getEntries()) {

                System.out.println("Title: " + entry.getTitle());

                System.out.println("Unique Identifier: " + entry.getUri());

                System.out.println("Updated Date: "

                        + entry.getUpdatedDate());


                // Get the Links

                for (SyndLinkImpl link : (List<SyndLinkImpl>) entry

                        .getLinks()) {

                    System.out.println("Link: " + link.getHref());

                }


                // Get the Contents

                for (SyndContentImpl content : (List<SyndContentImpl>) entry

                        .getContents()) {

                    System.out.println("Content: " + content.getValue());

                }


                // Get the Categories

     
展开阅读全文