android 开发之解析XML文件
2010-07-01 15:18:00 来源:WEB开发网*/
public void startDocument() throws SAXException {
forecastConditions = new ArrayList
googleWeather = new GoogleWeather();
}
/*
* 本方法在遇到新的XML节点时调用
*/
public void startElement(String namespaceURI, String localName,
String qName, Attributes atts) throws SAXException {
// 如果XML中完成了实时天气解析,那么开始解析未来几天天气
if (forecastTag) {
if (localName.equals("forecast_conditions")) {
// 当解析XML遇到forecast_conditions标签时,创建一个未来天气对象
gfc = new GForecastConditions();
}
if (localName.equals("day_of_week")) {
// 遇到day_of_week标签时,给赋值,读取data属性的值
gfc.setDayOfWeek(atts.getValue("data"));
}
if (localName.equals("low")) {
gfc.setLow(atts.getValue("data"));
}
if (localName.equals("high")) {
gfc.setHigh(atts.getValue("data"));
}
if (localName.equals("icon")) {
gfc.setIcon(atts.getValue("data"));
}
if (localName.equals("condition")) {
gfc.setCondition(atts.getValue("data"));
}
} else {
// 读取实时天气情况
if (localName.equals("condition")) {
googleWeather.setCondition(atts.getValue("data"));
}
if (localName.equals("temp_f")) {
googleWeather.setTempF(atts.getValue("data"));
}
if (localName.equals("temp_c")) {
googleWeather.setTempC(atts.getValue("data"));
}
if (localName.equals("humidity")) {
googleWeather.setHumidity(atts.getValue("data"));
}
if (localName.equals("icon")) {
googleWeather.setIcon(atts.getValue("data"));
}
更多精彩
赞助商链接