1.
private List<Person> list;
private List<Person> li;
li=isitData();
private List<Person> isitData() {
list=new ArrayList<Person>();
XmlPullParser parser = Xml.newPullParser();
try {
InputStream open = getAssets().open("data.xml");
parser.setInput(open, "utf-8");
int eventType = parser.getEventType();
while (eventType != XmlPullParser.END_DOCUMENT) {
String name = parser.getName();
switch (eventType) {
case XmlPullParser.START_TAG:
if ("cate".equals(name)) {
p = new Person();
}else if ("cate".equals(name)) {
p.setCate(parser.nextTag());
}else if ("cateurl".equals(name)) {
p.setCateurl(parser.nextText());
} else if ("catetitle".equals(name)) {
p.setCatetitle(parser.nextText());
}else if ("catecontent".equals(name)) {
p.setCatecontent(parser.nextText());
}else if ("cateprice".equals(name)) {
p.setCateprice(parser.nextText());
}
break;
case XmlPullParser.END_TAG:
if ("cate".equals(name)) {
list.add(p);
p = null;
}
break;
}
eventType = parser.next();
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return list;
}