您的位置:首页 > 移动开发 > Android开发

Android 从本地服务器下载文件与解析过程详解(三)

2013-02-05 16:44 561 查看
2、解析文件需要的代码:

java代码:

package eoe.xml;

import java.util.List;

import org.xml.sax.Attributes;

import org.xml.sax.SAXException;

import org.xml.sax.helpers.DefaultHandler;

import com.pisces.model.Mp3Info;

public class Mp3ListContentHandler extends DefaultHandler{

private List<Mp3Info> infos=null;

private Mp3Info mp3Info=null;

private String tagName=null;

@Override

public void characters(char[] ch, int start, int length)

throws SAXException {

String temp=new String(ch,start,length);

if(tagName.equals("id")){

mp3Info.setId(temp);

}else if(tagName.equals("mp3.name")){

mp3Info.setMp3Name(temp);

}else if(tagName.equals("mp3.size")){

mp3Info.setMp3Size(temp);

}else if(tagName.equals("lrc.name")){

mp3Info.setLrcName(temp);

}else if(tagName.equals("lrc.size")){

mp3Info.setLrcSize(temp);

}

}

@Override

public void endDocument() throws SAXException {

// TODO Auto-generated method stub

super.endDocument();

}

@Override

public void endElement(String uri, String localName, String qName)

throws SAXException {

if(localName.equals("resource")){

//此部分应注意

System.out.println("-----------");

infos.add(mp3Info);

}

tagName="";

}

public Mp3ListContentHandler(List<Mp3Info> infos) {

super();

this.infos = infos;

}

public List<Mp3Info> getInfos() {

return infos;

}

public void setInfos(List<Mp3Info> infos) {

this.infos = infos;

}

@Override

public void startDocument() throws SAXException {

// TODO Auto-generated method stub

super.startDocument();

}

@Override

public void startElement(String uri, String localName, String qName,

Attributes attributes) throws SAXException {

// TODO Auto-generated method stub

this.tagName=localName;

if(tagName.equals("resource")){

mp3Info=new Mp3Info();

}

}

}

复制代码
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: