public static List<News> XMLPull(InputStream is) {
List<News> list = null;
News news = null;
try {
XmlPullParser pull = Xml.newPullParser();
pull.setInput(is, "utf-8");
int eventType = pull.getEventType();
while (eventType != XmlPullParser.END_DOCUMENT) {
String name = pull.getName();
switch (eventType) {
case XmlPullParser.START_DOCUMENT:
list = new ArrayList<News>();
break;
case XmlPullParser.START_TAG:
if ("news".equalsIgnoreCase(name)) {
news = new News();
} else if ("title".equalsIgnoreCase(name)) {
news.setTitle(pull.nextText());
} else if ("body".equalsIgnoreCase(name)) {
news.setBody(pull.nextText());
} else if ("author".equalsIgnoreCase(name)) {
news.setAuthor(pull.nextText());
} else if ("pubDate".equalsIgnoreCase(name)) {
news.setPubDate(pull.nextText());
}
case XmlPullParser.END_TAG:
if ("news".equalsIgnoreCase(name)) {
Log.e("News", list.toString());
}
default:
break;
}
eventType = pull.next();
}
} catch (XmlPullParserException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return list;
}
List<News> list = null;
News news = null;
try {
XmlPullParser pull = Xml.newPullParser();
pull.setInput(is, "utf-8");
int eventType = pull.getEventType();
while (eventType != XmlPullParser.END_DOCUMENT) {
String name = pull.getName();
switch (eventType) {
case XmlPullParser.START_DOCUMENT:
list = new ArrayList<News>();
break;
case XmlPullParser.START_TAG:
if ("news".equalsIgnoreCase(name)) {
news = new News();
} else if ("title".equalsIgnoreCase(name)) {
news.setTitle(pull.nextText());
} else if ("body".equalsIgnoreCase(name)) {
news.setBody(pull.nextText());
} else if ("author".equalsIgnoreCase(name)) {
news.setAuthor(pull.nextText());
} else if ("pubDate".equalsIgnoreCase(name)) {
news.setPubDate(pull.nextText());
}
case XmlPullParser.END_TAG:
if ("news".equalsIgnoreCase(name)) {
Log.e("News", list.toString());
}
default:
break;
}
eventType = pull.next();
}
} catch (XmlPullParserException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return list;
}