本文转自:http://samwong.iteye.com/blog/1000403
android xml 的解析.
1.普通型
- <?xml version=”1.0″ ?>
- <statuses>
- <status>
- <source1>a</source1>
- <source2>a</source2>
- <source2>a</source2>
- </status>
- <statuses>
- </xml>
解析代码.
- try{
- xpp.setInput( new StringReader ( “xml string” ) );
- XmlPullParser parser = XmlPullParserFactory.newInstance()
- .newPullParser();
- int eventType = parser.getEventType();
- while (eventType != XmlPullParser.END_DOCUMENT) {
- if (eventType == XmlPullParser.START_TAG) {
- String name = parser.getName();
- Log.v(“tag”,parser.getName()+”=”+parser.next());
- }
- eventType = parser.next();
- }
- } catch (XmlPullParserException e) {
- } catch (Exception e) {
- }
2.嵌套子类.
- <?xml version=”1.0″ encoding=”UTF-8″ standalone=”no”?>
- <statuses>
- <status>
- <source1>a</source1>
- <source2>a</source2>
- <source2>a</source2>
- <user>
- <source1>a</source1>
- <source2>a</source2>
- <source2>a</source2>
- </user>