我正在按照本教程http://techiedreams.com/android-simple-rss-reader/开发一个 rss 阅读器应用程序。但是当我放一个博客 RSS 链接(比如这个http://blogname.com.br/feeds/posts/default?alt=rss)它不起作用。与此格式 www.site.com/index.php?format=feed&type=rss 的其他链接完美运行。哪个可能是问题?Bellow遵循解析器类。
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();
}
try {
//Criar as instâncias necessárias
DocumentBuilderFactory dbf;
dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
//Passa o xml
Document doc = db.parse(new InputSource(url.openStream()));
doc.getDocumentElement().normalize();
//Pega todas as tags
NodeList nl = doc.getElementsByTagName("item");
int length = nl.getLength();
for (int i = 0; i < length; i++) {
Node currentNode = nl.item(i);
RSSItem item = new RSSItem();
NodeList nchild = currentNode.getChildNodes();
int clength = nchild.getLength();
//Pegar os elementos requeridos de cada item
for (int j = 1; j < clength; j = j + 2) {
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)) {
// O valor do nó é "title", então devemos "setar"
// o valor do titulo de RSSItem
item.setTitle(theString);
} else if ("description".equals(nodeName)) {
item.setDescription(theString);
//Passa a descrição html para getar a url da imagem
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);
}
}
}
//adiciona elemento a lista
feed.addItem(item);
}
} catch (Exception e) {
}
//Retorna um objeto de RSSFeed, depois que todos os elementos foram adicionados a lista
return feed;
}
}
非常感谢,很抱歉英语很差。