使用Pull解析器解析 xml


public void test1() throws XmlPullParserException, IOException {

		InputStream inStream = new FileInputStream("/mnt/nand/songli.xml");

		XmlPullParser xmlParser = XmlPullParserFactory.newInstance()
				.newPullParser();
		xmlParser.setInput(inStream, "utf-8");
		int event = xmlParser.getEventType();
		String currTag = null;
		while (event != xmlParser.END_DOCUMENT) {
			switch (event) {
			case XmlPullParser.END_TAG:
				break;
			case XmlPullParser.START_TAG:
				currTag = xmlParser.getName();
				//以下为判断各各结点
				if("resp".equals(currTag)){
					String respCode = xmlParser.getAttributeValue(0);
					Log.i(TAG, respCode + "-----------------");
					//一下为活的courseSuit节点的属性
				} else if("courseSuit".equals(currTag)){
					int courrseCount = xmlParser.getAttributeCount();
					String courrs = xmlParser.getAttributeValue(1);
					Log.i(TAG, "-----------" + courrseCount  + courrs);
				} else if("courseItem".equals(currTag)){
					//可以或则courseItem结点下的所有内容
					String type = xmlParser.getAttributeName(0);
					String groupType = xmlParser.getAttributeName(1);
					String assetType = xmlParser.getAttributeName(2);
					String path = xmlParser.getAttributeName(3);
				}
				break;
					
			}
			event = xmlParser.next();
		}
	}

你可能感兴趣的:(解析xml、java)