在做一个Rss阅读器的小程序,第一次用sax解析xml文件,还是直接输入网址解析不知道这样写哪里错了。。好像没有解析 出什么东西,希望各位大大给点意见。谢谢
@Override
public void startElement(String namespaceURI,String localName,
    String qName,Attributes atts) throws SAXException{

if (localName.equals("item")){
this.in_item = true;
news = new News();
Log.d(TAG, "startElement is OK");
}else if(localName.equals("title")){

if(this.in_item){
this.in_title = true;
}else{
this.in_mainTitle = true;
}

}else if(localName.equals("link")){

if(this.in_item){
this.in_link = true;
}

}else if(localName.equals("description")){

if(this.in_item){
this.in_desc = true;
}

}else if(localName.equals("pubDate")){

if(this.in_item){
this.in_data = true;
}

}
}

解决方案 »

  1.   


    @Override
    public void endElement(String namespaceURI,String localName,
        String qName) throws SAXException{

    if (localName.equals("item")){
    this.in_item = false;
    list.add(news);
    Log.d(TAG, "endElement");

    }else if(localName.equals("title")){

    /*set News title and delete the character empty*/
    if(this.in_item){
    news.set_title(buf.toString().trim());
    buf.setLength(0);
    this.in_title = false;

    }else{
    /*set RSS title*/
    title = buf.toString().trim();
    buf.setLength(0);
    this.in_mainTitle = false;

    }

    }else if(localName.equals("link")){

    if(this.in_item){
    /*set News link*/
    news.set_link(buf.toString().trim());
    buf.setLength(0);
    this.in_link = false;
    }

    }else if(localName.equals("description")){

    if(this.in_item){
    /*set News description*/
    news.set_desc(buf.toString().trim());
    buf.setLength(0);
    this.in_desc = false;

    }

    }else if(localName.equals("pubDate")){

    if(this.in_item){
    /*set News pubDate*/
    news.set_data(buf.toString().trim());
    buf.setLength(0);
    this.in_data = false;
    }

    }
    }