Im getting Rss from a site. in the description tag there is an image that i would like to show to the users. I m using this code to get it:
public void setDescription(String description) {
this.description = description;
//parse description for any image or video links
if (description.contains("<img style=")){
String imgg = description.substring(description.indexOf("<img style="));
String cleanUp = imgg.substring(0, imgg.indexOf(">")+1);
imgg = imgg.substring(imgg.indexOf("src=") + 5);
int indexOf = imgg.indexOf("\"");
if (indexOf==-1){
indexOf = imgg.indexOf("\"");
}
imgg = imgg.substring(0, indexOf);
setImgLink(imgg);
this.description = this.description.replace(cleanUp, "");
} else{
String imgg2="replace_image.png";
setImgLink(imgg2);
}
}
My problem is that if the site i m getting the rss changes something in the xml,i m getting my replace image.For example,if the img style change to image src or something like this.
Is there any way to fix it and get everytime the images from the description??
I have found that i can use something like this but i can’t make it work http://developer.android.com/reference/android/text/Html.html
Thanks!:)
Rather than using regex its better to use DOM and XPATH to extract the image source. This way even if the HTML changes, your solution will still work.
It seems you have the description in
descriptionand you want the image path inimgg. Try this: