0
votes

i am creating an android app which fetches information from rss feeds...till now i can successfully parsing a single rss feed...and display whatever i need.

I want to parse multiple RSS feeds and filter it based on the tags given on those sites...most of the rss will be feedburner rss.

Is there a way to combine many rss feeds filter it based on tags,keywords etc..... and create a single rss feed

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;
        }
    }
1

1 Answers

0
votes

You can do this non-programmatically using Yahoo Pipes - it allows you to "pipe", filter and aggregate RSS data into a single feed.