Lecture Notes
Weather Forecast
-- How to parse XML files
May 4th, 2017
res/raw/[Link]
<?xml version=1.0 encoding= utf-8?>
<infos>
<city id=sh>
<name> Shanghai </name>
<temp> 20/30 </temp>
<weather> Cloudy </weather>
<pm> 80</pm>
<wind>Level 3</wind>
</city>
<city id=bj>
<name> Beijing </name>
<temp> 16/25 </temp>
<weather> Sunny </weather>
<pm>1 80</pm>
<wind>Level 1</wind>
</city>
<city id=gz>
<name> Guangzhou</name>
<temp> 27/35 </temp>
<weather>Sunny </weather>
<pm> 70</pm>
<wind>Level2</wind>
</city>
</infos>
XML Parsing Methods
1. DOM
2. SAX
3. PULL---- XmlPullParser
Step1: XMLPullParser parser= [Link]();
Step2: [Link]( InputStream is, String encoding-format);
Step 3: while loop
Int type= [Link]();
while (type != XmlPullParser. END_DOCUMENT){
switch(type){
case XmlPullParser.START_TAG:
[Link]();
[Link]();
.
break;
case XmlPullParser.END_TAG:
[Link]();
[Link]();
break;
}
Type= [Link](); //go to the next event type
}//while loop