-1
A
回答
0
你应该使用xmlpullparser或SAX解析器或DOM解析器对XML的RSS提要解析 尝试这个例子
try {
URL url = new URL("http://news.yahoo.com/rss/entertainment");
XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
factory.setNamespaceAware(false);
XmlPullParser xpp = factory.newPullParser();
// We will get the XML from an input stream
xpp.setInput(getInputStream(url), "UTF_8");
/* We will parse the XML content looking for the "<title>" tag which appears inside the "<item>" tag.
* However, we should take in consideration that the rss feed name also is enclosed in a "<title>" tag.
* As we know, every feed begins with these lines: "<channel><title>Feed_Name</title>...."
* so we should skip the "<title>" tag which is a child of "<channel>" tag,
* and take in consideration only "<title>" tag which is a child of "<item>"
*
* In order to achieve this, we will make use of a boolean variable.
*/
boolean insideItem = false;
// Returns the type of current event: START_TAG, END_TAG, etc..
int eventType = xpp.getEventType();
while (eventType != XmlPullParser.END_DOCUMENT) {
if (eventType == XmlPullParser.START_TAG) {
if (xpp.getName().equalsIgnoreCase("item")) {
insideItem = true;
} else if (xpp.getName().equalsIgnoreCase("title")) {
if (insideItem)
headlines.add(xpp.nextText()); //extract the headline
} else if (xpp.getName().equalsIgnoreCase("link")) {
if (insideItem)
links.add(xpp.nextText()); //extract the link of article
}
}else if(eventType==XmlPullParser.END_TAG && xpp.getName().equalsIgnoreCase("item")){
insideItem=false;
}
eventType = xpp.next(); //move to next element
}
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (XmlPullParserException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
public InputStream getInputStream(URL url) {
try {
return url.openConnection().getInputStream();
} catch (IOException e) {
return null;
}
}
相关问题
- 1. 从雅虎rss feed解析媒体内容源xcode 4.5 ios
- 2. 解析Android中的RSS源
- 3. 雅虎天气api解析
- 4. 雅虎查询语言 - RSS
- 5. 解析雅虎财经CSV用的NodeJS
- 6. 如何解析雅虎BOSS API响应
- 7. 雅虎管道保留旧的RSS源从发布
- 8. Android从ASPX解析RSS源URL
- 9. 在Android中解析RSS源描述
- 10. 解析reddit的RSS源 - PHP
- 11. 无法解析从雅虎财经API返回的csv在android
- 12. 雅虎YQL RSS没有返回结果
- 13. 在雅虎管道中输出(rss)
- 14. python feedparser与雅虎天气rss
- 15. 雅虎天气rss feed加拿大
- 16. 雅虎YQL RSS - 错误请求
- 17. 雅虎管道 - RSS没有超链接?
- 18. GWT使用雅虎使用RSS/XML
- 19. 雅虎管道和自定义rss
- 20. TBXML解析器解析一个RSS源
- 21. XML :: RSS ::解析器和Facebook RSS源...
- 22. 用JQuery解析WordPress RSS源
- 23. 用PHP解析RSS源
- 24. 雅虎Android中的集成
- 25. 解析Android中的CDATA RSS
- 26. 解决雅虎999块?
- 27. RSS解析图像Android
- 28. 在Android上解析RSS
- 29. PHP:解析RSS源的文本?
- 30. Python中的RSS源解析器库
嘿,非常感谢...!有用。我能够提取所有数据项。但是我也需要提取“media:content”的属性作为“url”来显示新闻图片。多一点帮助PLZ ... :) – Rider
你试过媒体内容的网址标签 – skyshine