我正在尝试获取网站的内容并使其显示在Android应用程序中,因此我按照使用SAX解析器来解析网站的XML内容的教程,
所以根据我创建的RSS HANDLER CLASS的指令,该类的功能是SAX Parser遍历整个XML文件,每当遇到开始标记时,都会调用endElement方法并为localname变量分配其名称,我在getTitle(),getthumb()等中遇到错误,所以请任何人纠正我做过的错误..
这是我的RSS处理程序代码.. enter code here
class RSSHandler扩展了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();
}