private void readXml() throws XmlPullParserException, IOException {
XmlPullParser parser = XmlPullParserFactory.newInstance().newPullParser();
parser.setInput(openFileInput("peoples.xml"), "utf-8");
int type = parser.getEventType();
ArrayList<People> arrayList = null;
People p = null;
while (type != XmlPullParser.END_DOCUMENT) {
switch (type) {
case XmlPullParser.START_TAG:
if ("peoples".equals(parser.getName())) {
arrayList = new ArrayList<People>();
} else if ("people".equals(parser.getName())) {
p = new People();
} else if ("name".equals(parser.getName())) {
p.setName(parser.nextText());
} else if ("age".equals(parser.getName())) {
p.setAge(Integer.parseInt(parser.nextText()));
}
break;
case XmlPullParser.END_TAG:
if ("people".equals(parser.getName())) {
arrayList.add(p);
p = null;
}
break;
}
type = parser.next();
}
for (People pp : arrayList) {
System.out.println(pp.getName() + " " + pp.getAge());
}
}