0% found this document useful (0 votes)
31 views2 pages

Weather Forecast: Lecture Notes

This document contains lecture notes on weather forecasting and parsing XML files. It includes an XML file containing weather data for three Chinese cities - Shanghai, Beijing, Guangzhou - including temperature, weather conditions, pollution levels and wind levels. It also outlines three methods for parsing XML - DOM, SAX, and PULL using an XML pull parser, detailing the steps to initialize and parse through an XML file using a pull parser.

Uploaded by

Abdulla Alim
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
31 views2 pages

Weather Forecast: Lecture Notes

This document contains lecture notes on weather forecasting and parsing XML files. It includes an XML file containing weather data for three Chinese cities - Shanghai, Beijing, Guangzhou - including temperature, weather conditions, pollution levels and wind levels. It also outlines three methods for parsing XML - DOM, SAX, and PULL using an XML pull parser, detailing the steps to initialize and parse through an XML file using a pull parser.

Uploaded by

Abdulla Alim
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Lecture Notes

Weather Forecast

-- How to parse XML files

May 4th, 2017

res/raw/weather.xml
<?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= XML.newPullParser();
Step2: parser.setInput( InputStream is, String encoding-format);
Step 3: while loop
Int type= parser.getEventType();
while (type != XmlPullParser. END_DOCUMENT){

switch(type){
case XmlPullParser.START_TAG:
parser.getName();
parser.nextText();
.
break;
case XmlPullParser.END_TAG:
parser.getName();
parser.nextText();

break;
}
Type= parser.next(); //go to the next event type
}//while loop

You might also like