public WeatherData GetForecastWeatherData(string locId, bool force) { var result = new WeatherData(); if (String.IsNullOrEmpty(locId)) { return(null); } try { if (!LoadWeatherData(locId, force, true)) { return(null); } var data = new XmlDocument(); data.Load(_cacheDir + "/" + locId + ".forecast.xml"); var ns = new XmlNamespaceManager(data.NameTable); ns.AddNamespace("yweather", "http://xml.weather.yahoo.com/ns/rss/1.0"); XmlNode node = data.SelectSingleNode("/rss/channel/yweather:units", ns); result.TempUnit = node.Attributes["temperature"].InnerText; node = data.SelectSingleNode("/rss/channel/yweather:location", ns); result.LocationName = node.Attributes["city"].InnerText; node = data.SelectSingleNode("/rss/channel/item/yweather:condition", ns); result.Today = new WeatherCurrentDetail { Temperature = node.Attributes["temp"].InnerText, Icon = node.Attributes["code"].InnerText }; result.Forecast.Clear(); XmlNodeList nodes = data.SelectNodes("/rss/channel/item/yweather:forecast", ns); var diff = 0; foreach (XmlNode inode in nodes) { var temp = new WeatherForecastDetail { DayDiff = diff, DayName = inode.Attributes["day"].InnerText, DayDate = inode.Attributes["date"].InnerText, DayIcon = inode.Attributes["code"].InnerText, NightIcon = inode.Attributes["code"].InnerText, MaxTemp = inode.Attributes["high"].InnerText, LowTemp = inode.Attributes["low"].InnerText }; result.Forecast.Add(temp); diff++; } return(result); } catch (XmlException) { } catch (XPathException) { } catch (IOException) { } catch (NullReferenceException) { } return(null); }
public WeatherData GetForecastWeatherData(string locId, bool force) { var result = new WeatherData(); if (String.IsNullOrEmpty(locId)) return null; try { if (!LoadWeatherData(locId, force, true)) return null; var data = new XmlDocument(); data.Load(_cacheDir + "/" + locId + ".forecast.xml"); var ns = new XmlNamespaceManager(data.NameTable); ns.AddNamespace("yweather", "http://xml.weather.yahoo.com/ns/rss/1.0"); XmlNode node = data.SelectSingleNode("/rss/channel/yweather:units", ns); result.TempUnit = node.Attributes["temperature"].InnerText; node = data.SelectSingleNode("/rss/channel/yweather:location", ns); result.LocationName = node.Attributes["city"].InnerText; node = data.SelectSingleNode("/rss/channel/item/yweather:condition", ns); result.Today = new WeatherCurrentDetail { Temperature = node.Attributes["temp"].InnerText, Icon = node.Attributes["code"].InnerText }; result.Forecast.Clear(); XmlNodeList nodes = data.SelectNodes("/rss/channel/item/yweather:forecast", ns); var diff = 0; foreach (XmlNode inode in nodes) { var temp = new WeatherForecastDetail { DayDiff = diff, DayName = inode.Attributes["day"].InnerText, DayDate = inode.Attributes["date"].InnerText, DayIcon = inode.Attributes["code"].InnerText, NightIcon = inode.Attributes["code"].InnerText, MaxTemp = inode.Attributes["high"].InnerText, LowTemp = inode.Attributes["low"].InnerText }; result.Forecast.Add(temp); diff++; } return result; } catch (XmlException) { } catch (XPathException) { } catch (IOException) { } catch (NullReferenceException) { } return null; }