如何在rss feed的xml解析中获取<img src=""/>

时间:2014-04-10 08:30:45

标签: android

如何获取网址<img src=''>一个RSS源并在android

中打开
<description>
<img src="http://static.ibnlive.in.com/ibnlive/pix/sitepix/03_2010/google_new_630_90x62.jpg" alt="REDIRECTED: Google shut its Chinese portal over censorship and visitors were being redirected to Hong Kong-based site." title="REDIRECTED: Google shut its Chinese portal over censorship and visitors were being redirected to Hong Kong-based site." border="0" width="70" height="50" align="left" hspace="5"/>The company joins Google in protesting cyber attacks and censorship in China.
</description>

2 个答案:

答案 0 :(得分:2)

如果您想从上面的URL获得XML,可以尝试使用jsoup库:

String input = "<description>\n" +
            "<img src=\"http://static.ibnlive.in.com/ibnlive/pix/sitepix/03_2010/google_new_630_90x62.jpg\"" +
            " alt=\"REDIRECTED: Google shut its Chinese portal over censorship and visitors were being redirected" +
            " to Hong Kong-based site.\" title=\"REDIRECTED: Google shut its Chinese portal" +
            " over censorship and visitors were being redirected to Hong Kong-based site.\"" +
            " border=\"0\" width=\"70\" height=\"50\" align=\"left\" hspace=\"5\"/>The company" +
            " joins Google in protesting cyber attacks and censorship in China.\n" +
            "</description>";
Document document = Jsoup.parse(input);
String output = document.select("img").first().attr("src");

答案 1 :(得分:1)

首先你应该使用RssParser获取描述字符串,然后将该字符串发送到此方法。你不需要图书馆。当然首先你应该用你的答案替换“with”来匹配你的例子,并在我的代码中选择一个特殊的单词,你的img url中存在“equals”。就像你的问题中存在的“pix”一样。

private String helperString(String str) {
    String[] strings = str.split("'");
    for (String string: strings) {
        Log.i("STR", "string : " + string);
        String[] newString = string.split("/");
        for (String a: newString) {
            if (a.equals("images")){  //in your question pix or other words
                Log.i("URL", "Image Url is : " + string);
                return string;
            }
        }
    }
    return "";
}