Friday, April 12, 2013

[android help] Andriod XML Parsing using SAXParser


I have My Rss File Items :




Prasad
http://www.tele.com/rssHostDescr.php?hostId=15
http://www.tele.com/rssHostDescr.php?hostId=14
2013-04-10
Prasad



........................


etc.....................


I'm trying to parse the above file,I'm able to get all the information(title,link,date)but my requirement is to get url attribute value,How to get the URL value from media:thumbnail tag? Could any one help?


here my code:



public class HostsRssHandler extends DefaultHandler {
private List messages;
private HostsProfile currentMessage;
private StringBuilder builder;

public List getMessages(){
return messages;
}
@Override
public void characters(char[] ch, int start, int length)
throws SAXException {
super.characters(ch, start, length);
builder.append(ch, start, length);
}
@Override
public void endElement(String uri, String localName, String name)
throws SAXException {
super.endElement(uri, localName, name);
if (this.currentMessage != null){
if (localName.equalsIgnoreCase("tilte")){
currentMessage.setTitle(builder.toString());
} else if (localName.equalsIgnoreCase("link")){
currentMessage.setLink(builder.toString());
}
else if (localName.equalsIgnoreCase("media:thumbnail")){
currentMessage.setMediathumbnail(builder.toString());
}
else if (localName.equalsIgnoreCase("pubDate")){
currentMessage.setDate(builder.toString());
}


else if (localName.equalsIgnoreCase("item")){
messages.add(currentMessage);
}
builder.setLength(0);
}
}

@Override
public void startDocument() throws SAXException {
super.startDocument();
messages = new ArrayList();
builder = new StringBuilder();
}

@Override
public void startElement(String uri, String localName, String name,
Attributes attributes) throws SAXException {
super.startElement(uri, localName, name, attributes);
if (localName.equalsIgnoreCase("item")){
this.currentMessage = new HostsProfile();
}
}
}


Note:



else if (localName.equalsIgnoreCase("media:thumbnail")){
currentMessage.setMediathumbnail(builder.toString());// During My Program Execution, Here I'm not able to get any value
}


.

stackoverflow.comm

No comments:

Post a Comment

Google Voice on T-Mobile? [General]

Google Voice on T-Mobile? So I recently switched from a GNex on Verizon to a Moto X DE on T-Mobile. I had always used Google Voice for my v...