0

我正在创建一个从 rss 提要中获取信息的 android 应用程序...直到现在我可以成功解析单个 rss 提要...并显示我需要的任何内容。

我想解析多个 RSS 提要并根据这些站点上给出的标签对其进行过滤……大多数 RSS 将是 feedburner RSS。

有没有办法结合许多 rss 提要根据标签、关键字等过滤它......并创建单个 rss 提要

public class BaseFeedParser {
    static String feedUrlString = "http://feeds.dzone.com/dzone/frontpage";

        // names of the XML tags
        static final String RSS = "rss";
        static final String CHANNEL = "channel";
        static final String ITEM = "item";

        static final String PUB_DATE = "pubDate";
        static final String DESCRIPTION = "description";
        static final String LINK = "link";
        static final String TITLE = "title";

        private final URL feedUrl;

        protected BaseFeedParser(){
            try {
                this.feedUrl = new URL(feedUrlString);
            } catch (MalformedURLException e) {
                throw new RuntimeException(e);
            }
        }

        protected InputStream getInputStream() {
            try {
                return feedUrl.openConnection().getInputStream();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }

        public List<Message> parse() {
            final Message currentMessage = new Message();
            RootElement root = new RootElement(RSS);
            final List<Message> messages = new ArrayList<Message>();
            Element itemlist = root.getChild(CHANNEL);
            Element item = itemlist.getChild(ITEM);
            item.setEndElementListener(new EndElementListener(){
                public void end() {
                    messages.add(currentMessage.copy());
                }
            });
            item.getChild(TITLE).setEndTextElementListener(new EndTextElementListener(){
                public void end(String body) {
                    currentMessage.setTitle(body);
                }
            });
            item.getChild(LINK).setEndTextElementListener(new EndTextElementListener(){
                public void end(String body) {
                    currentMessage.setLink(body);
                }
            });
            item.getChild(DESCRIPTION).setEndTextElementListener(new EndTextElementListener(){
                public void end(String body) {
                    currentMessage.setDescription(body);
                }
            });
            item.getChild(PUB_DATE).setEndTextElementListener(new EndTextElementListener(){
                public void end(String body) {
                    currentMessage.setDate(body);
                }
            });
            try {
                Xml.parse(this.getInputStream(), Xml.Encoding.UTF_8, root.getContentHandler());
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
            return messages;
        }
    }
4

1 回答 1

0
于 2012-08-10T02:26:03.560 回答