Pull parsing
Pull's XML parsing operations are similar to sax parsing operations and are also event-driven. The corresponding event code is triggered when the XML document starts parsing or encounters a node.
The main concerns are two classes:
Org.xmlpull.v1.XmlPullParserFactory
Org.xmlpull.v1.XmlPullParser
To parse an XML file using Xmlpull:
1. Create a factory class
Xmlpullparserfactory factory = Xmlpullparserfactory.newinstance ();
2. Create Parser
Xmlpullparser xpp = Factory.newpullparser ();
3. Set the input stream, which is what to parse
Xpp.setinput (Input, "GBK"); This is mainly composed of two forms, character stream (e.g. StringReader) or byte stream (e.g. FileInputStream)
4. Through the loop, parse the content
int eventtype = Xpp.geteventtype (); Have to have
while (eventtype! = xmlpullparser.end_document) {
if (EventType = = xmlpullparser.start_document) {
all = new arraylist<linkman> ();
} else if (EventType = = Xmlpullparser.start_tag) {
ElementName = Xpp.getname ();
if ("Linkman". Equals (ElementName)) {
man = new Linkman ();
}
} else if (EventType = = Xmlpullparser.end_tag) {
ElementName = Xpp.getname ();
if ("Linkman". Equals (ElementName)) {
All.add (man);
man = null;
}
} else if (EventType = = Xmlpullparser.text) {
if ("Name". Equals (ElementName)) {
Man.setname (Xpp.gettext ());
} else if ("email". Equals (ElementName)) {
Man.setemail (Xpp.gettext ());
}
}
EventType = Xpp.next (); Be sure to have
}
Pull generate XML document
Need to take advantage of ORG.XMLPULL.V1. XmlSerializer
Android's Xmlpull