android解析xml的通用写法

try {
ByteArrayInputStream is = new ByteArrayInputStream(data.getBytes());
XmlPullParser parser = XmlPullParserFactory.newInstance().newPullParser();
parser.setInput(is, "UTF-8");
int eventType = parser.getEventType();
while (eventType != XmlPullParser.END_DOCUMENT) {
Log.i("name", eventType+"");
String name = parser.getName();
switch (eventType) {
case XmlPullParser.START_DOCUMENT:
dataList = new ArrayList<CheckingRaw>();
break;
case XmlPullParser.START_TAG:
if ("row".equals(name)) {
checkingRaw = new CheckingRaw();
} else if ("P1".equals(name)) {
checkingRaw.setName(parser.nextText());
} else if ("P2".equals(name)) {
checkingRaw.setArea(parser.nextText());
} else if ("P3".equals(name)) {
checkingRaw.setGroupName(parser.nextText());
} else if ("P5".equals(name)) {
checkingRaw.setScore(parser.nextText());
} else if ("P6".equals(name)) {
checkingRaw.setRanking(parser.nextText());
}


break;
case XmlPullParser.END_TAG:
if ("row".equals(name)) {
dataList.add(checkingRaw);
checkingRaw = null;
}
default:
break;
}
eventType = parser.next();
}

你可能感兴趣的:(android,xml,String,null)