在做一个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;
}
}
}
@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;
}
}
}
解决方案 »
- android的mount命令怎么用
- 用apktool反编译apk文件得到smali文件夹,里面都是*.smali文件怎么回事?
- JNI:封装Android中Canvas类下的drawBitmap()函数问题请教!
- Activity 中 onTouchEvent 没有执行...
- android的演示程序
- 获取后台数据
- 开发android软件,哪个开发平台比较成熟,资料比较多的?
- [Android]应用图标只当做一个开关 ??
- adt安装出现问题
- android:onclick="selftDestruct ",运行时出现找不到selftDestruct方法的错误,求大神指教!
- View的绘图实现机制
- android SAX解析XML文件
@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;
}
}
}