下图的xml怎么解析并把数据放到listview里
2016-03-01
展开全部
类似这样
static public List<DataKlb> ParseXmlQueryKlb(String xmlStr){
List<DataKlb> list = null;
DataKlb data = null;
XmlPullParser parser = Xml.newPullParser();
try {
parser.setInput(new StringReader(xmlStr));
int event = parser.getEventType();
while(event != XmlPullParser.END_DOCUMENT){
String nodeName=parser.getName();
switch (event) {
case XmlPullParser.START_DOCUMENT:
list = new ArrayList<DataKlb>();
break;
case XmlPullParser.START_TAG:
if("DrvPreasign".equalsIgnoreCase(nodeName)){
data = new DataKlb();
} else if("ID".equalsIgnoreCase(nodeName)){
data.id = parser.nextText();
} else if("Name".equalsIgnoreCase(nodeName)){
data.name = parser.nextText();
}
break;
case XmlPullParser.END_TAG:
if("DrvPreasign".equalsIgnoreCase(nodeName)){
list.add(data);
}
break;
default:
break;
}
event = parser.next();
}
return list;
} catch (XmlPullParserException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
static public List<DataKlb> ParseXmlQueryKlb(String xmlStr){
List<DataKlb> list = null;
DataKlb data = null;
XmlPullParser parser = Xml.newPullParser();
try {
parser.setInput(new StringReader(xmlStr));
int event = parser.getEventType();
while(event != XmlPullParser.END_DOCUMENT){
String nodeName=parser.getName();
switch (event) {
case XmlPullParser.START_DOCUMENT:
list = new ArrayList<DataKlb>();
break;
case XmlPullParser.START_TAG:
if("DrvPreasign".equalsIgnoreCase(nodeName)){
data = new DataKlb();
} else if("ID".equalsIgnoreCase(nodeName)){
data.id = parser.nextText();
} else if("Name".equalsIgnoreCase(nodeName)){
data.name = parser.nextText();
}
break;
case XmlPullParser.END_TAG:
if("DrvPreasign".equalsIgnoreCase(nodeName)){
list.add(data);
}
break;
default:
break;
}
event = parser.next();
}
return list;
} catch (XmlPullParserException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询