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();
}
}
}
复制代码
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();
}
}
}
复制代码
相关文章推荐
- Android 从本地服务器下载文件与解析过程详解(一)
- Android 从本地服务器下载文件与解析过程详解(二)
- Android 从本地服务器下载文件与解析过程详解(四)
- Android 从本地服务器下载文件与解析过程详解(五)
- Android中measure过程、WRAP_CONTENT详解以及xml布局文件解析流程浅析(上)
- Android中measure过程、WRAP_CONTENT详解以及xml布局文件解析流程浅析(下)
- Android init.rc文件解析过程详解(一)
- Android中measure过程、WRAP_CONTENT详解以及xml布局文件解析流程浅析(下)
- 【转载】Android中measure过程、WRAP_CONTENT详解以及xml布局文件解析流程浅析(下)
- Android init.rc文件解析过程详解(一)
- Android中measure过程、WRAP_CONTENT详解以及xml布局文件解析流程浅析(下)
- Android从远程服务器下载文件到本地sd卡中
- Android init.rc文件解析过程详解(三)
- Android中measure过程、WRAP_CONTENT详解以及xml布局文件解析流程浅析(下)
- Android中measure过程、WRAP_CONTENT详解以及xml布局文件解析流程浅析(上)
- Android init.rc文件解析过程详解(一)
- Android解析本地服务器的XML文件
- 【转载】Android中measure过程、WRAP_CONTENT详解以及xml布局文件解析流程浅析(上)
- Android init.rc文件解析过程详解(一)
- [原创]Android init.rc文件解析过程详解(二)