码迷,mamicode.com
首页 > 移动开发 > 详细

Android 解析 xml

时间:2016-02-10 19:54:31      阅读:201      评论:0      收藏:0      [点我收藏+]

标签:

URL httpUrl = new URL(url);
HttpURLConnection conn = (HttpURLConnection )httpUrl.openConnection();
conn.setRequestMethod("GET");
conn.setReadTimeout(5000);
InputStream in = conn.getInputSteam();
XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
XmlPullParser parser = factory.newPullParser();
parser.setInput(in,"UTF-8");
int eventType = parser.getEventType();
final List<Girl> list = new ArrayList<Girl>();

Girl girl = null;
while(eventType != XmlPullParser.END_DOCUMENT){
String data = parser.getName();
swich(eventType){
case XmlPullParser.START_TAG:
if("gril".equals(data)){
girl = new Girl();
}
if("name".equals(data)){
girl.setName(parser.nextText());
}
break;
case XmlPullParser.END_TAG:
if("girl".equals(data)&&girl != null){
list.add(girl);  
}
bradk;
}  
eventType = parser.next();
}

 

Android 解析 xml

标签:

原文地址:http://www.cnblogs.com/luoxiaolei/p/5186085.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!