我从服务器返回一个XML流并解析xml流,但是通知了这个错误包 to this
private Boolean parseXml(InputStream iStream)
throws XmlPullParserException, IOException {
// TODO Auto-generated method stub
News news = null;
// 用pull解析器解析
XmlPullParser parser = Xml.newPullParser();
parser.setInput(iStream, null);
int event = parser.getEventType();
while (event != XmlPullParser.END_DOCUMENT) {
switch (event) {
case XmlPullParser.START_DOCUMENT:
if (newes == null) {
throw new IllegalArgumentException("newes 参数不能为空");
}
Log.i(TAG_SERVICE, "开始解析xml文件");
break;
case XmlPullParser.START_TAG:
Log.i(TAG_SERVICE, "遇到启始标签 " + parser.getName());
if ("news1".equals(parser.getName())) {
String id = parser.getAttributeType(0);
news = new News();
news.setId(Integer.valueOf(id));
}
if ("title1".equals(parser.getName())) {
news.setTitle(parser.nextText());
}
if ("age1".equals(parser.getName())) {
news.setAge(Integer.valueOf(parser.nextText()));
}
break;
case XmlPullParser.END_TAG:
Log.i(TAG_SERVICE, "遇到结束标签 " + parser.getName());
if ("news1".equals(parser.getName())) {
newes.add(news);
news = null;
}
break;
default:
break;
}
event = parser.next();
}
return true;
}