从android中的RSS feed获取图像URL

时间:2012-04-11 13:33:55

标签: android xml rss rss-reader

我一直在开发一个Android RSS阅读器。我想从RSS提要中获取图像并将它们与RSS标题一起列出。我已经解析并从“标题”和“描述”标签中提取数据。可以告诉我任何人如何从“描述”的“src”属性下面获取图像URL?

<item>
    <title>Bollywood now more professional, but impersonal: Anupam Kher</title>
    <link>
        http://www.abcd.com/en/node/599
    </link>
    <description>
        <div class=" field field-type-filefield field-field-story-image">
            <div class="field-label">Image:&amp;nbsp;</div>
            <div class="field-items">
                <div class="field-item odd">
                    <img class="imagefield imagefield-field_story_image" width="630" height="420" alt="" src="http://www.madhyamam.com/en/sites/default/files/anumpamkher2.jpg?1334148050" />
                </div>
            </div>
        </div>
        <p>
            <strong>New Delhi: </strong>He has been part of the film industry for almost three decades.
        </p>
        <a href="http://www.abcd.com/en/node/599" target="_blank">read more</a>
    </description>
</item>

2 个答案:

答案 0 :(得分:1)

首先,在AsyncTask中进行解析。在此任务中,您只需以加载的HTML / XML格式下载图像。

在后台加载URL时,您可以调用以下例程:

private Bitmap getImageFromURL(URL imgUrl){
        Bitmap bmp = null;

        try {
            HttpURLConnection conn= (HttpURLConnection)imgUrl.openConnection();
            conn.setDoInput(true);
            conn.connect();
            InputStream is = conn.getInputStream();

            bmp = BitmapFactory.decodeStream(is);
       } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
       }
       return bmp;  
    }

答案 1 :(得分:-1)

我找到了解决方案......

                        News news=new News();    

                        String img  = news.Description[i];
                        String cleanUp = img.substring(0, img.indexOf(">")+1);
                        img = img.substring(img.indexOf("src=") + 5);
                        int indexOf = img.indexOf("'");
                            if (indexOf==-1){
                            indexOf = img.indexOf("\"");
                           }
                        img = img.substring(0, indexOf);
                        news.image[i]=img;