Mufad Mufad - 1 month ago 12
Android Question

Parsing image link from media:thumbnail tag of RSS feed android

I'm trying to parse data from this RSS feed

http://www.thedailystar.net/frontpage/rss.xml

I'm using AsyncTask and I can parse all other tags except "media:thumbnail"
Here's the code

for (int i = 0; i < items.getLength(); i++) {
Node currentchild = items.item(i);
if (currentchild.getNodeName().equalsIgnoreCase("item")) {
NewsItems item=new NewsItems();
NodeList itemchilds = currentchild.getChildNodes();
for (int j = 0; j < itemchilds.getLength(); j++) {
Node current = itemchilds.item(j);
if (current.getNodeName().equalsIgnoreCase("title")){
item.setTitle(current.getTextContent());
}else if (current.getNodeName().equalsIgnoreCase("description")){
item.setDescription(current.getTextContent());
}else if (current.getNodeName().equalsIgnoreCase("media:thumbnail")){
item.setMedia(current.getTextContent());//This is not working
}else if (current.getNodeName().equalsIgnoreCase("link")){
item.setUrl(current.getTextContent());
}
}


I've checked the previous answers regarding this problem, but none of them are working for me.

Thanks!

Answer

getTextContent() isn't working because that node doesn't have any text content.

You have to access the "url" attribute of the node.

getAttributes().getNamedItem("url").getTextContent()

Comments