解析XML件遇到字符串时public void characters(char[] ch, int start, int length)会调用两次,并且第二次是在endelement后调用的会产生\t\t,刚开始解析也是先调用characters,不是startlement,弄好久了,实在不知道怎么弄了,下面是解析用到的方法
@Override
public void characters(char[] ch, int start, int length)
throws SAXException {
String temp=new String(ch,start,length);
if(tagname.equals("name")){
Mp3content.setName(temp);
}
if(tagname.equals("size")){
Mp3content.setSize(temp);
}
if(tagname.equals("singer")){
Mp3content.setSinger(temp);
}
super.characters(ch, start, length);
}
@Override
public void endDocument() throws SAXException {
super.endDocument();
}
@Override
public void endElement(String uri, String localName, String qName)
throws SAXException {
if(localName=="mp3"){
System.out.println(localName+"------>2.1");
System.out.println(Mp3content.getSize()+"----");
list.add(Mp3content);
tagname="";
}
super.endElement(uri, localName, qName);
}
public myContenthandler() {
super();
}
@Override
public void startDocument() throws SAXException {
super.startDocument();
}
@Override
public void startElement(String uri, String localName, String qName,
Attributes attributes) throws SAXException {
this.tagname=localName;
if(localName=="mp3"){
Mp3content=new mp3content();
}
super.startElement(uri, localName, qName, attributes);
}
这是那份XML文件
<?xml version="1.0" encoding="utf-8"?>
rwr
2322
rwdd
utg
865
mfd
还有些错误提示和警告也不知道怎么处理
03-17 10:24:37.946: E/InputDispatcher(70): channel '40748430 com.example.mp3players/com.example.mp3players.Mp3ListActivity (server)' ~ Consumer closed input channel or an error occurred. events=0x8
快来大神帮帮小弟我啊,怎么弄啊