綁定帳號登入

Android 台灣中文網

打印 上一主題 下一主題

[求助] 抓取XML來使用氣象APP

[複製連結] 查看: 1368|回覆: 0|好評: 0
跳轉到指定樓層
樓主
gn01871733 | 收聽TA | 只看該作者 回帖獎勵 |倒序瀏覽 |閱讀模式
發表於 2012-9-12 14:44

馬上加入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

先謝謝看文回文的各位了!!!



「用Android 就來APK.TW」,快來加入粉絲吧!
Android 台灣中文網(APK.TW)
收藏收藏1 分享分享 分享專題
用Android 就來Android 台灣中文網(https://apk.tw)
回覆

使用道具 舉報

您需要登錄後才可以回帖 登錄 | 註冊

本版積分規則