Pull parsing FOR XML:
//class loader loading XML file
InputStream is = MainActivity.class.getClassLoader (). getResourceAsStream ("Weather.xml");
Pull parser to generate XML
Xmlpullparser pull = Xml.newpullparser ();
try {
Setting the input stream
Pull.setinput (IS, "utf-8");
The state that the parser is currently in
int type = Pull.geteventtype ();
Weather Weather = null;
while (type! = xmlpullparser.end_document) {
Switch (type) {
Node that is currently the start tag
Case Xmlpullparser.start_tag:
Get the name of the node tag
String name = Pull.getname ();
Determine the name of the node tag (below) and place it in the weather object
if ("Channel". Equals (name)) {
weather = new weather ();
Weather.setid (pull.getattributevalue (0));
}
if ("City". Equals (name)) {
Weather.setname (Pull.nexttext ());
}
if ("Temp". Equals (name)) {
weather.settemp (Pull.nexttext ());
}
if ("Wind". Equals (name)) {
Weather.setwind (Pull.nexttext ());
}
break;
If this is the end tag node, place the Weather object in the list collection to save
Case Xmlpullparser.end_tag:
String tagname = Pull.getname ();
if ("Channel". Equals (tagname)) {
List.add (weather);
}
Default
break;
}
Must be written here, otherwise it will not be executed down
Type = Pull.next ();
}
} catch (Exception e) {
E.printstacktrace ();
}
}
This article is from the "Beginner" blog, so be sure to keep this source http://10154241.blog.51cto.com/10144241/1664205
Pull parsing of XML in Android