Java Reference
In-Depth Information
catch(Exception e) {
System.out.println(e.toString());
e.printStackTrace();
}
}
Listing 13-12 shows this in action with the LocationParser class that uses the kXML
parser to parse XML into a Location object.
Listing 13-12. Using the kXML Parser
package com.apress.rischpater.weatherwidget;
import org.kxml2.io.*;
import java.io.*;
public class LocationParser {
private Location location;
private boolean setForecast;
private boolean hasForecast;
private boolean setTemp;
private String precipitation, precipType, precipProb;
private String windSpeed, windDirection;
private StringBuffer buffer;
public LocationParser() {
location = new Location();
}
public LocationParser(Location l) {
location = l;
}
public void parse(ByteArrayInputStream in) {
try {
InputStreamReader reader = new InputStreamReader(in);
KXmlParser parser = new KXmlParser();
boolean keepParsing = true;
parser.setInput(reader);
while(keepParsing) {
int type = parser.next();
 
Search WWH ::




Custom Search