开发学院手机开发Android 开发 android 开发之解析XML文件 阅读

android 开发之解析XML文件

 2010-07-01 15:18:00 来源:WEB开发网   
核心提示:*/public void startDocument() throws SAXException {forecastConditions = new ArrayList();googleWeather = new GoogleWeather();}/** 本方法在遇到新的XML节点时调用*/public void s

*/

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"));

}

上一页  1 2 3 4 5 6  下一页

Tags:android 开发 解析

编辑录入:coldstar [复制链接] [打 印]
[]
  • 好
  • 好的评价 如果觉得好,就请您
      0%(0)
  • 差
  • 差的评价 如果觉得差,就请您
      0%(0)
赞助商链接