Question

I Have been developing an Android RSS reader.I want to fetch the images from RSS feed and list them along with RSS title.I have parsed,and fetched data from "title" and "description" tags.Can Anyone tell me how to get the image URL from below "src" property of "description" ?

<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>
Was it helpful?

Solution 2

I have found the solution.....

                        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;

OTHER TIPS

First of all, do the parsing in an AsyncTask. In this task you can simply download the images in the HTML/XML you load.

When you load the URL in the background you can call the following routine:

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;  
    }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top