如何在android中从RSS提要XML提取图像URL

如何在android中从RSS提要XML提取图像URL,android,xml,rss,android-xmlpullparser,Android,Xml,Rss,Android Xmlpullparser,目前我正在开发一个应用程序,可以读取和显示RSS数据的提要,我能够解析和显示文章的标题RSS提要是BBC新闻和文章的描述,我还希望能够为每个条目添加缩略图 以下是XML的结构: <item> <title>Major earthquake strikes Nepal</title> <description>A magnitude 7.3 earthquake strikes eastern Nepal, two weeks afte

目前我正在开发一个应用程序,可以读取和显示RSS数据的提要,我能够解析和显示文章的标题RSS提要是BBC新闻和文章的描述,我还希望能够为每个条目添加缩略图

以下是XML的结构:

<item> 
  <title>Major earthquake strikes Nepal</title>  
  <description>A magnitude 7.3 earthquake strikes eastern Nepal, two weeks after a devastating quake that killed more than 8,000 people.</description>  
  <link>http://www.bbc.co.uk/news/world-asia-32701385#sa-ns_mchannel=rss&amp;ns_source=PublicRSS20-sa</link>  
  <guid isPermaLink="false">http://www.bbc.co.uk/news/world-asia-32701385</guid>  
  <pubDate>Tue, 12 May 2015 11:37:06 GMT</pubDate>  
  <media:thumbnail width="66" height="49" url="http://news.bbcimg.co.uk/media/images/82937000/jpg/_82937953_b060dce4-16b1-4c1f-8cb5-412a744930f9.jpg"/>  
  <media:thumbnail width="144" height="81" url="http://news.bbcimg.co.uk/media/images/82937000/jpg/_82937954_b060dce4-16b1-4c1f-8cb5-412a744930f9.jpg"/> 
</item>  

Item是一个类,它包含标题、描述和URL获取者和设置者,以便在各种文本视图和图像视图中显示数据

String url = "";
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
InputSource is = new InputSource(new StringReader(xml));
Document document = db.parse(is);
NodeList nodeList = document.getElementsByTagName("Item");
for(int i=0; i<nodeList.getLength(); i++) {
    url = nodeList.item(i).getAttributes().getNamedItem("url").getNodeValue();
} //or if it is always only one item -> url = nodeList.item(0).getAttributes().getNamedItem("url").getNodeValue();
然后可以将url设置为项目对象

String url = "";
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
InputSource is = new InputSource(new StringReader(xml));
Document document = db.parse(is);
NodeList nodeList = document.getElementsByTagName("Item");
for(int i=0; i<nodeList.getLength(); i++) {
    url = nodeList.item(i).getAttributes().getNamedItem("url").getNodeValue();
} //or if it is always only one item -> url = nodeList.item(0).getAttributes().getNamedItem("url").getNodeValue();