我正在尝试解析并显示来自Feed中的图片,该Feed包含标记内的imgage URL。一个例子是:
*Note>> http://someImage.jpg不是真正的图片链接,这只是一个例子。这是我到目前为止所做的。
public void startElement(String uri, String localName, String qName, Attributes atts) {
chars = new StringBuilder();
if (qName.equalsIgnoreCase("content:encoded")) {
if (!atts.getValue("src").toString().equalsIgnoreCase("null")) {
feedStr.setImgLink(atts.getValue("src").toString());
Log.d(TAG, "inside if " + feedStr.getImgLink());
} else {
feedStr.setImgLink("");
Log.d(TAG, feedStr.getImgLink());
}
}
}
我相信我的编程部分需要调整。首先,当qName等于“content:encoded”时,解析停止。应用程序只是无休止地运行而不显示任何内容第二,如果我改变那个初始,如果qName不能像“purplebunny”那样的东西,一切都很完美,除了没有图像。我错过了什么?我正确使用atts.getValue吗?我已经使用log来查看ImgLink中出现的内容,它始终为null。
答案 0 :(得分:0)
您可以将content:encoded
数据存储在字符串中。然后,您可以通过此库Jsoup
示例强>:
假设存储在content:encoded
变量中的Description
原始数据。
Document doc = Jsoup.parse(Description);
Element image =doc.select("img").first();
String url = image.absUrl("src");