List<Entry> list = new ArrayList<>();
Entry entry = null;
try {
int eventType = response.getEventType();
while(XmlPullParser.END_DOCUMENT != eventType){
switch (eventType){
case XmlPullParser.START_TAG:
String tag = response.getName();
if ("item".equalsIgnoreCase(tag)){
entry = new Entry(); }else if (entry != null){
if ("title".equalsIgnoreCase(tag)){
entry.setTitle(new String(response.nextText().getBytes(),"UTF-8"));
}else if ("description".equalsIgnoreCase(tag)){
entry.setDesc(new String(response.nextText().getBytes(),"UTF-8"));
}else if ("link".equalsIgnoreCase(tag)){
entry.setUrl(response.nextText());
}
}
break;
case XmlPullParser.END_TAG:
if (response.getName().equalsIgnoreCase("item") && entry != null) {
list.add(entry);
entry = null;
}
break;
default:
break;
}
eventType = response.next();
}
}catch (XmlPullParserException e) {
Log.e(TAG,"xml parse error :"+e.getLocalizedMessage());
} catch (IOException e) {
Log.e(TAG,"xml parse error IOException:"+e.getLocalizedMessage());
}

上面是第一种

 try {
int eventType = response.getEventType();
while(XmlPullParser.END_DOCUMENT != eventType){
switch (eventType){
case XmlPullParser.START_TAG:
String tag = response.getName();
if ("entry".equalsIgnoreCase(tag)){
entry = new Entry(); }else if (entry != null){
if ("title".equalsIgnoreCase(tag)){
entry.setTitle(new String(response.nextText().getBytes(),"UTF-8"));
}else if ("content".equalsIgnoreCase(tag)){
entry.setDesc(new String(response.nextText().getBytes(),"UTF-8"));
}else if ("link".equalsIgnoreCase(tag)){
entry.setUrl(response.getAttributeValue(null, "href"));
}
}
break;
case XmlPullParser.END_TAG:
if (response.getName().equalsIgnoreCase("entry") && entry != null) {
list.add(entry);
entry = null;
}
break;
default:
break;
}
eventType = response.next();
}
}catch (XmlPullParserException e) {
Log.e(TAG,"xml parse error :"+e.getLocalizedMessage());
} catch (IOException e) {
Log.e(TAG,"xml parse error IOException:"+e.getLocalizedMessage());
}

上面是第二种

最新文章

  1. [转]ExtJs基础--Html DOM、Ext Element及Component三者之间的区别
  2. 继续畅通工程-Floyd
  3. Python的平凡之路(4)
  4. 求s=a+aa+aaa+aaaa+aa...a的值,其中a是一个数字。
  5. 项目总结—jQuery EasyUI- DataGrid使用
  6. idea常用快捷键大全(转)
  7. 【转】U-boot分析与移植(1)----bootloader分析
  8. 仿QQ注册验证码的实现。
  9. 单点登录系统(SSO)的开发思路
  10. c#类似单片机的8bit或运算
  11. zoj 1004 dfs
  12. 【webpack学习笔记】a01-基础构建
  13. 20175320 2018-2019-2 《Java程序设计》第1周学习总结
  14. $nextTick 的作用
  15. QL Server 高可用性(一)AlwaysOn 技术
  16. 如何优雅打印nginx header和body
  17. 请问实现MVC的框架有哪些,实现持久化操作的框架有哪些,还有类似于spring整合的框架又有哪些
  18. [c/c++]指针(3)
  19. java中生成流水号的一个例子(使用关系型数据库)
  20. Zynq学习笔记(1)——Hellow World

热门文章

  1. AWK 脚本编写习惯
  2. JS原型与原型链终极详解(转)
  3. 一篇关于学C++的感想(拿来与大家分享)
  4. Could not find action or result 导致 页面出现404错误
  5. Java抽奖小程序
  6. ASP.net后台弹出消息对话框的方法!【转】
  7. PHPstrom 增加emmet插件
  8. Aspose.word总结
  9. 如何编写规范,灵活,稳定,高质量的HTML和css代码
  10. JS获得QQ号码的昵称,头像,生日