1
votes

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>
2
You have to parse your xml first. - MAC
yeah..I have parsed it..and fetched data from <title> and <description> tags.But I want to know is how to fetch the image URL frm "src" property of <description> - Basim Sherif
What are you parsing it with? SAX? - Cheesebaron
iam using this method to generate custom listview.. androidhive.info/2012/02/… in that example, the RSS feed contains a <image> tag so that we can easily fetch image URL.But in my RSS feed,there is no <image> tag. I have to get the image URL frm "src" property of <description> tag.... - Basim Sherif

2 Answers

1
votes

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;  
    }
-1
votes

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;