You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

86 lines
2.7 KiB

package com.example.myapplication;
import android.util.Xml;
import org.xmlpull.v1.XmlPullParser;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
class jierihuochu{
static List<jieriInfo> getInfofosfrom(InputStream is)throws Exception{
XmlPullParser parser = Xml.newPullParser();
parser.setInput(is,"utf-8");
List<jieriInfo> jieriInfos = null;
jieriInfo jieriinfo = null;
int type = parser.getEventType();
while (type!= XmlPullParser.END_DOCUMENT){
switch (type){
case XmlPullParser.START_TAG:
if("infos".equals(parser.getName())){
jieriInfos = new ArrayList<jieriInfo>();
}else if("jieri".equals(parser.getName())){
jieriinfo = new jieriInfo();
String ids = parser.getAttributeValue(0);
jieriinfo.setid(ids);
}else if("temp".equals(parser.getName())){
String temp = parser.nextText();
assert jieriinfo != null;
jieriinfo.settemp(temp);
}
else if("shijian".equals(parser.getName())){
String shijian = parser.nextText();
assert jieriinfo != null;
jieriinfo.setshijian(shijian);
}
else if("huodong".equals(parser.getName())){
String huodong = parser.nextText();
assert jieriinfo != null;
jieriinfo.sethuodong(huodong);
}
break;
case XmlPullParser.END_TAG:
if("jieri".equals(parser.getName())){
assert jieriInfos != null;
jieriInfos.add(jieriinfo);
jieriinfo = null;
}
break;
}
type = parser.next();
}
return jieriInfos;
}
}
class jieriInfo{
private String id;
private String temp;
private String shijian;
private String huodong;
public String getid(){
return id;
}
void setid(String id){
this.id = id;
}
String gettemp(){
return temp;
}
void settemp(String temp){
this.temp = temp;
}
String getshijian(){
return shijian;
}
void setshijian(String shijian){
this.shijian = shijian;
}
String gethuodong(){
return huodong;
}
void sethuodong(String huodong){
this.huodong = huodong;
}
}