最近遇到一个坑,我在网上找了一段代码来解析XML,片段如下:
int eventType = xpp.getEventType(); while (eventType != XmlPullParser.END_DOCUMENT) { if(eventType == XmlPullParser.START_DOCUMENT) { System.out.println("Start document"); } else if(eventType == XmlPullParser.END_DOCUMENT) { System.out.println("End document"); } else if(eventType == XmlPullParser.START_TAG) { System.out.println("Start tag "+xpp.getName()); } else if(eventType == XmlPullParser.END_TAG) { System.out.println("End tag "+xpp.getName()); } else if(eventType == XmlPullParser.TEXT) { System.out.println("Text "+xpp.getText()); } eventType = xpp.next(); }
final int depth = parser.getDepth(); int type = parser.next(); while ((type != XmlPullParser.END_TAG || parser .getDepth() > depth) && type != XmlPullParser.END_DOCUMENT) { ...//next }
XmlPullParser 解析不到END_DOCUMENT,XmlPullParserException: Unexpected token (position:TEXT
原文地址:http://blog.csdn.net/bigconvience/article/details/45127253