Wednesday, April 17, 2013

[android help] Parse Enclosure tag using AndroidSaxFeedParser


I want to parse the 'url' attribute in enclosure tag


I have seen only samples using DefaultHandler.any way to do it using AndroidSaxFeedParser


Enclosure tag is inside the tag Item


Code: public List parse() throws IOException, SAXException { final Message currentMessage = new Message(); RootElement root = new RootElement(RSS); final List messages = new ArrayList(); Element channel = root.getChild(CHANNEL);



channel.getChild(LASTBUILDATE).setEndTextElementListener(new EndTextElementListener(){
public void end(String body) {
lastBuildDate = body;
}
});
Element item = channel.getChild(ITEM);

item.setEndElementListener(new EndElementListener(){
public void end() {
currentMessage.setLastBuildDate(lastBuildDate);
messages.add(currentMessage.copy());
}
});
item.getChild(TITLE).setEndTextElementListener(new EndTextElementListener(){
public void end(String body) {
currentMessage.setTitle(body);
}
});
item.getChild(LINK).setEndTextElementListener(new EndTextElementListener(){
public void end(String body) {
currentMessage.setLink(body);
}
});


item.getChild(DESCRIPTION).setEndTextElementListener(new EndTextElementListener(){
public void end(String body) {
currentMessage.setDescription(body);
}
});
item.getChild(PUB_DATE).setEndTextElementListener(new EndTextElementListener(){
public void end(String body) {
currentMessage.setDate(body);
}
});
item.getChild(CATEGORY).setEndTextElementListener(new EndTextElementListener(){
public void end(String body) {
currentMessage.setCategory(body);
}
});
item.getChild(GUID).setEndTextElementListener(new EndTextElementListener(){
public void end(String body) {
currentMessage.setGuid(body);
}
});

Xml.parse(this.getInputStream(), Xml.Encoding.UTF_8, root.getContentHandler());
return messages;
}


.

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...