首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在rss提要的xml解析中获取

如何在rss提要的xml解析中获取
EN

Stack Overflow用户
提问于 2014-04-10 16:30:45
回答 2查看 1.7K关注 0票数 0

如何在android中获取url <img src=''>并打开rss feed

代码语言:javascript
复制
<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>
EN

回答 2

Stack Overflow用户

发布于 2014-04-10 17:04:45

如果你想从上面的XML获取一个URL,你可以尝试使用jsoup库:

代码语言:javascript
复制
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");
票数 2
EN

Stack Overflow用户

发布于 2015-07-31 19:06:00

首先,您应该使用RssParser获取描述字符串,然后将该字符串发送到此方法。你不需要去图书馆。当然,首先你应该用‘代替’来匹配你的例子和我的答案,并选择一个特殊的单词,它只存在于你的img url中,代表我的代码中的"equals“,比如你问题中存在的"pix”单词。

代码语言:javascript
复制
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 "";
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/22982725

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档