Android 我们可以解析包含链接标签的Rss提要吗?链接标签包含html格式的图像
我正在做一个手机更新项目,这是一款Android应用程序,需要每天更新市场上新推出的手机 为此,我使用了以下链接: 通过使用链接的rss提要:() 并从中获得了提要的标题和描述,但无法获得图像,我无法理解如何解析它 根据示例代码修改的我的Dom解析器代码:Android 我们可以解析包含链接标签的Rss提要吗?链接标签包含html格式的图像,android,xml,parsing,rss,Android,Xml,Parsing,Rss,我正在做一个手机更新项目,这是一款Android应用程序,需要每天更新市场上新推出的手机 为此,我使用了以下链接: 通过使用链接的rss提要:() 并从中获得了提要的标题和描述,但无法获得图像,我无法理解如何解析它 根据示例代码修改的我的Dom解析器代码: package com.example.mobileupdates.parser; import java.net.MalformedURLException; import java.net.URL; import javax.xml.
package com.example.mobileupdates.parser;
import java.net.MalformedURLException;
import java.net.URL;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.jsoup.Jsoup;
import org.jsoup.select.Elements;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.InputSource;
public class DOMParser {
private RSSFeed _feed = new RSSFeed();
public RSSFeed parseXml(String xml) {
URL url = null;
try {
url = new URL(xml);
} catch (MalformedURLException e1) {
e1.printStackTrace();
System.out.println(e1.getMessage());
}
try {
// Create required instances
DocumentBuilderFactory dbf;
dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
// Parse the xml
Document doc = db.parse(new InputSource(url.openStream()));
doc.getDocumentElement().normalize();
// Get all <item> tags.
NodeList nl = doc.getElementsByTagName("item");
int length = nl.getLength();
for (int i = 0; i < length; i++) {
Node currentNode = nl.item(i);
System.out.println(nl.getLength());
RSSItem _item = new RSSItem();
NodeList nchild = currentNode.getChildNodes();
int clength = nchild.getLength();
System.out.println("length" + clength);
System.out.println("nodes" + nchild);
// Get the required elements from each Item
for (int j = 0; j < clength; j = j + 1) {
Node thisNode = nchild.item(j);
String theString = null;
String nodeName = thisNode.getNodeName();
theString = nchild.item(j).getFirstChild().getNodeValue();
if (theString != null) {
if ("title".equals(nodeName)) {
// Node name is equals to 'title' so set the Node
// value to the Title in the RSSItem.
_item.setTitle(theString);
}
else if ("description".equals(nodeName)) {
_item.setDescription(theString);
// Parse the html description to get the image url
String html = theString;
org.jsoup.nodes.Document docHtml = Jsoup
.parse(html);
Elements imgEle = docHtml.select("img");
_item.setImage(imgEle.attr("src"));
}
else if ("pubDate".equals(nodeName)) {
// We replace the plus and zero's in the date with
// empty string
String formatedDate = theString.replace(" +0000",
"");
_item.setDate(formatedDate);
}
}
}
// add item to the list
_feed.addItem(_item);
}
} catch (Exception e) {
}
// Return the final feed once all the Items are added to the RSSFeed
// Object(_feed).
return _feed;
}
}
By changing this block of code i got title and description but no image obtained
// Get the required elements from each Item
for (int j = 0; j < clength; j = j + 1) {
please help me in obtaining it or can we have any other ways to do thi application without rss feeds
package com.example.mobileupdates.parser;
导入java.net.MalformedURLException;
导入java.net.URL;
导入javax.xml.parsers.DocumentBuilder;
导入javax.xml.parsers.DocumentBuilderFactory;
导入org.jsoup.jsoup;
导入org.jsoup.select.Elements;
导入org.w3c.dom.Document;
导入org.w3c.dom.Node;
导入org.w3c.dom.NodeList;
导入org.xml.sax.InputSource;
公共类DOMParser{
私有RSSFeed_feed=新RSSFeed();
公共RSSFeed解析xml(字符串xml){
URL=null;
试一试{
url=新url(xml);
}捕获(格式错误的异常e1){
e1.printStackTrace();
System.out.println(e1.getMessage());
}
试一试{
//创建所需的实例
DocumentBuilderFactoryDBF;
dbf=DocumentBuilderFactory.newInstance();
DocumentBuilder db=dbf.newDocumentBuilder();
//解析xml
Document doc=db.parse(新的输入源(url.openStream());
doc.getDocumentElement().normalize();
//获取所有标签。
NodeList nl=doc.getElementsByTagName(“项目”);
int length=nl.getLength();
for(int i=0;i