馬上加入Android 台灣中文網,立即免費下載應用遊戲。
您需要 登錄 才可以下載或查看,沒有帳號?註冊
x
不知道這個問題在這邊問對不對(汗
小弟最近使用了Yahoo Weather 提供的 XML 檔來讀取氣象資料
但不知道為甚麼
在抓取LocalName的時候只抓的到最後一個"guid"
XML在此 : http://weather.yahooapis.com/forecastrss?w=2306179
程式碼如下:
public void startElement(String uri, String localName, String qName,
Attributes attributes) throws SAXException {
// 地點
if (localName.equals("yweather:location")) {
String value = attributes.getValue("city");
myWeatherInfo.Set_location(value);
}
// 圖片
else if (localName.equals("yweather:condition")) {
String value = attributes.getValue("code");
myWeatherInfo.Set_weather_Icon(value);
}
// 溫度(C)
else if (localName.equals("yweather:condition")) {
String value = attributes.getValue("temp");
myWeatherInfo.Set_temp(value);
}
// 濕度
else if (localName.equals("yweather:atmosphere")) {
String value = attributes.getValue("humidity");
myWeatherInfo.Set_humpercent(value);
}
// 能見度
else if (localName.equals("yweather:atmosphere")) {
String value = attributes.getValue("visibility");
myWeatherInfo.Set_vispercent(value);
}
// 日期
else if (localName.equals("yweather:condition")) {
String value=attributes.getValue("date");
myWeatherInfo.Set_date(value);
}
爬了不少文章,發現有些人也是差不多這樣的方式去寫
但不知道為甚麼整個XML只能抓到最後一個LocalName,也就是我沒有要使用的guid
先謝謝看文回文的各位了!!!
|
|