I'm trying to fetch the content of website and making it to display in the android app, so i followed the tutorial which uses SAX parser to parse the XML content of the website,
so according to the instruction I had created RSS HANDLER CLASS the functionality of that class is the SAX Parser traverses through the entire XML file and whenever it comes across an opening tag occurs then the endElement method gets called and the localname variable gets assigned with its name, I'm getting error in getTitle(), getthumb() etc., so please can anybody correct the mistake I had done..
here is my RSS Handler code.. enter code here
class RSSHandler extends DefaultHandler {
private static final String PostList = null;
private Post currentPost = new Post();
StringBuffer chars = new StringBuffer();
@Override
public void startElement(String uri, String localName, String qName,
Attributes atts) {
chars = new StringBuffer();
if (localName.equalsIgnoreCase("item")) {
}
}
@Override
public void endElement(String uri, String localName, String qName)
throws SAXException {
if (localName.equalsIgnoreCase("title")
&& currentPost.getTitle() == null) {
currentPost.setTitle(chars.toString());
}
if (localName.equalsIgnoreCase("pubDate")
&& currentPost.getPubDate() == null) {
currentPost.setPubDate(chars.toString());
}
if (localName.equalsIgnoreCase("thumbnail")
&& currentPost.getThumbnail() == null) {
currentPost.setThumbnail(chars.toString());
}
if (localName.equalsIgnoreCase("link")
&& currentPost.getUrl() == null) {
currentPost.setUrl(chars.toString());
}
if (localName.equalsIgnoreCase("item")) {
PostList.add(currentPost);
currentPost = new Post();
}