1. 初始化一个xml的解析器
XmlPullParser parser = Xml.newPullParser();
2. 设置解析器的参数
InputStream inputStream = this.getAssets().open("10001.xml"); parser.setInput(inputStream, "utf-8");
3. 读数据
int eventType = pullParser.getEventType();//获取一个标记 while(eventType != pullParser.END_DOCUMENT){//只要标记不等于文档的末尾就一直解析 if (eventType == pullParser.START_TAG) { if ("name".equals(pullParser.getName())) { sb.append(pullParser.nextText()+","); } else if ("age".equals(pullParser.getName())) { sb.append(pullParser.nextText()+","); } } eventType = pullParser.next();//不能忘
时间: 2024-12-21 17:32:28