コード例 #1
0
ファイル: Weather.cs プロジェクト: RikerCabra/YANSM
        public static List<Conditions> GetForecastConditions()
        {
            List<Conditions> forecast = new List<Conditions>();

            XmlDocument xmlConditions = new XmlDocument();
            xmlConditions.Load(BuildUrl("forecast/city"));

            if (xmlConditions.SelectSingleNode("/weatherdata/location/name") == null)
            {
                Conditions noCity = new Conditions();
                noCity.City = "City Not Found";
                forecast.Add(noCity);
            }
            else
            {
                XmlNodeList nodeList = xmlConditions.GetElementsByTagName("forecast");
                foreach(XmlNode node in nodeList)
                {
                    foreach(XmlNode timeNode in node.ChildNodes)
                    {
                        Conditions forecastedCondition = new Conditions();
                        forecastedCondition.City = xmlConditions.SelectSingleNode("/weatherdata/location/name").InnerText;
                        forecastedCondition.Temp = timeNode.SelectSingleNode("temperature").Attributes["value"].Value;
                        forecastedCondition.Time = timeNode.Attributes["from"].Value;
                        if (timeNode.SelectSingleNode("precipitation").Attributes["type"] != null)
                            forecastedCondition.Condition = timeNode.SelectSingleNode("precipitation").Attributes["type"].Value;

                        forecast.Add(forecastedCondition);
                    }
                }
            }

            return forecast;
        }
コード例 #2
0
ファイル: Weather.cs プロジェクト: RikerCabra/YANSM
        public static Conditions GetCurrentConditions()
        {
            Conditions current = new Conditions();

            XmlDocument xmlConditions = new XmlDocument();
            xmlConditions.Load(BuildUrl("weather"));

            if(xmlConditions.SelectSingleNode("/current/city") == null)
            {
                current.City = "City Not Found";
            }
            else
            {
                current.City = xmlConditions.SelectSingleNode("/current/city").Attributes["name"].Value;
                current.Condition = xmlConditions.SelectSingleNode("/current/weather").Attributes["value"].Value;
                current.Temp = xmlConditions.SelectSingleNode("/current/temperature").Attributes["value"].Value;

            }

            return current;
        }