我正在创建一个Android应用程序,它从rss提要中获取信息......到现在为止,我可以成功解析单个RSS提要...并显示我需要的任何内容。
我想解析多个RSS源并根据这些站点上给出的标签对其进行过滤...大部分rs都是feedburner rss。
有没有办法合并多个RSS Feed,根据标签,关键字等对其进行过滤.....并创建单个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;
}
}