org.xmlpull.v1.XmlPullParserException:意外的标记(位置:java.io.InputStreamReader@126fda23中的未知@ 5:1)

时间:2016-08-24 11:12:12

标签: java android

我从服务器返回一个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;
        }

0 个答案:

没有答案