Esempio n. 1
0
        private void ParseYahooWeatherDoc(XmlDocument xDoc)
        {
            //Setting up NSManager
            XmlNamespaceManager man = new XmlNamespaceManager(xDoc.NameTable);

            man.AddNamespace("yweather", "http://xml.weather.yahoo.com/ns/rss/1.0");

            this.Unit            = xDoc.SelectSingleNode("rss/channel/yweather:units", man).Attributes["temperature"].Value.ToString();
            this.CodeDescription = xDoc.SelectSingleNode("rss/channel/item/yweather:condition", man).Attributes["text"].Value.ToString();
            this.Location        = xDoc.SelectSingleNode("rss/channel/yweather:location", man).Attributes["city"].Value.ToString();
            this.Temp            = xDoc.SelectSingleNode("rss/channel/item/yweather:condition", man).Attributes["temp"].Value.ToString();
            this.Code            = xDoc.SelectSingleNode("rss/channel/item/yweather:condition", man).Attributes["code"].Value.ToString();
            this.ImageUrl        = string.Format("resx://MediaBrowser/MediaBrowser.Resources/_{0}", this.Code);
            //this.ImageUrl = string.Format("http://l.yimg.com/a/i/us/we/52/{0}.gif", this.Code);
            this.LongTemp = string.Format("{0}°{1} {2}", Temp, Unit, CodeDescription);

            var tempForecast = xDoc.SelectNodes("rss/channel/item/yweather:forecast", man);

            //<yweather:forecast day="Fri" date="24 Apr 2009" low="50" high="63" text="Partly Cloudy" code="30" />
            foreach (XmlNode temp in tempForecast)
            {
                ForecastItem fi = new ForecastItem();
                fi.Day             = temp.Attributes["day"].Value.ToString();
                fi.Date            = temp.Attributes["date"].Value.ToString();
                fi.Low             = temp.Attributes["low"].Value.ToString();
                fi.High            = temp.Attributes["high"].Value.ToString();
                fi.Code            = temp.Attributes["code"].Value.ToString();
                fi.CodeDescription = temp.Attributes["text"].Value.ToString();
                fi.ImageUrl        = string.Format("resx://MediaBrowser/MediaBrowser.Resources/_{0}", fi.Code);
                _forecast.Add(fi);
            }
        }
        private void ParseYahooWeatherDoc(XmlDocument xDoc)
        {
            //Setting up NSManager
            XmlNamespaceManager man = new XmlNamespaceManager(xDoc.NameTable);

            man.AddNamespace("yweather", "http://xml.weather.yahoo.com/ns/rss/1.0");

            Unit         = xDoc.SelectSingleNode("query/results/channel/yweather:units", man).Attributes["temperature"].Value.ToString();
            SpeedUnit    = xDoc.SelectSingleNode("query/results/channel/yweather:units", man).Attributes["speed"].Value.ToString();
            PressureUnit = xDoc.SelectSingleNode("query/results/channel/yweather:units", man).Attributes["pressure"].Value.ToString();
            DistanceUnit = xDoc.SelectSingleNode("query/results/channel/yweather:units", man).Attributes["distance"].Value.ToString();

            CodeDescription  = xDoc.SelectSingleNode("query/results/channel/item/yweather:condition", man).Attributes["text"].Value.ToString();
            Location         = xDoc.SelectSingleNode("query/results/channel/yweather:location", man).Attributes["city"].Value.ToString();
            Humidity         = xDoc.SelectSingleNode("query/results/channel/yweather:atmosphere", man).Attributes["humidity"].Value.ToString();
            VisibileDistance = xDoc.SelectSingleNode("query/results/channel/yweather:atmosphere", man).Attributes["visibility"].Value.ToString();
            Chill            = xDoc.SelectSingleNode("query/results/channel/yweather:wind", man).Attributes["chill"].Value.ToString();
            Direction        = xDoc.SelectSingleNode("query/results/channel/yweather:wind", man).Attributes["direction"].Value.ToString();
            Speed            = xDoc.SelectSingleNode("query/results/channel/yweather:wind", man).Attributes["speed"].Value.ToString();
            Pressure         = xDoc.SelectSingleNode("query/results/channel/yweather:atmosphere", man).Attributes["pressure"].Value.ToString();
            Sunrise          = xDoc.SelectSingleNode("query/results/channel/yweather:astronomy", man).Attributes["sunrise"].Value.ToString();
            Sunset           = xDoc.SelectSingleNode("query/results/channel/yweather:astronomy", man).Attributes["sunset"].Value.ToString();
            Temp             = xDoc.SelectSingleNode("query/results/channel/item/yweather:condition", man).Attributes["temp"].Value.ToString();
            Code             = xDoc.SelectSingleNode("query/results/channel/item/yweather:condition", man).Attributes["code"].Value.ToString();
            ImageUrl         = string.Format("resx://MediaBrowser/MediaBrowser.Resources/_{0}", this.Code);
            //this.ImageUrl = string.Format("http://l.yimg.com/a/i/us/we/52/{0}.gif", this.Code);
            LongTemp       = string.Format("{0}°{1} {2}", Temp, Unit, CodeDescription);
            LongPressure   = string.Format("{0} {1}", Pressure, PressureUnit);
            LongWindSpeed  = string.Format("{0} {1} {2}", Speed, SpeedUnit, Direction);
            LongVisibility = string.Format("{0} {1}", VisibileDistance, DistanceUnit);

            var tempForecast = xDoc.SelectNodes("query/results/channel/item/yweather:forecast", man);

            //<yweather:forecast day="Fri" date="24 Apr 2009" low="50" high="63" text="Partly Cloudy" code="30" />
            foreach (XmlNode temp in tempForecast)
            {
                var fi = new ForecastItem();
                fi.Day             = temp.Attributes["day"].Value.ToString();
                fi.Date            = temp.Attributes["date"].Value.ToString();
                fi.Low             = temp.Attributes["low"].Value.ToString();
                fi.High            = temp.Attributes["high"].Value.ToString();
                fi.Code            = temp.Attributes["code"].Value.ToString();
                fi.CodeDescription = temp.Attributes["text"].Value.ToString();
                fi.ImageUrl        = string.Format("resx://MediaBrowser/MediaBrowser.Resources/_{0}", fi.Code);
                if (_forecast.Count < 2)
                {
                    _forecast.Add(fi);
                }
                _extendedForecast.Add(fi);
                if (_extendedForecast.Count > 5)
                {
                    break;                              //limit to 6 days
                }
            }
        }
Esempio n. 3
0
        private void ParseYahooWeatherDoc(XmlDocument xDoc)
        {
            //Setting up NSManager
            XmlNamespaceManager man = new XmlNamespaceManager(xDoc.NameTable);
            man.AddNamespace("yweather", "http://xml.weather.yahoo.com/ns/rss/1.0");

            Unit = xDoc.SelectSingleNode("rss/channel/yweather:units", man).Attributes["temperature"].Value.ToString();
            SpeedUnit = xDoc.SelectSingleNode("rss/channel/yweather:units", man).Attributes["speed"].Value.ToString();
            PressureUnit = xDoc.SelectSingleNode("rss/channel/yweather:units", man).Attributes["pressure"].Value.ToString();
            DistanceUnit = xDoc.SelectSingleNode("rss/channel/yweather:units", man).Attributes["distance"].Value.ToString();

            CodeDescription = xDoc.SelectSingleNode("rss/channel/item/yweather:condition", man).Attributes["text"].Value.ToString();
            Location = xDoc.SelectSingleNode("rss/channel/yweather:location", man).Attributes["city"].Value.ToString();
            Humidity = xDoc.SelectSingleNode("rss/channel/yweather:atmosphere", man).Attributes["humidity"].Value.ToString();
            VisibileDistance = xDoc.SelectSingleNode("rss/channel/yweather:atmosphere", man).Attributes["visibility"].Value.ToString();
            Chill = xDoc.SelectSingleNode("rss/channel/yweather:wind", man).Attributes["chill"].Value.ToString();
            Direction = xDoc.SelectSingleNode("rss/channel/yweather:wind", man).Attributes["direction"].Value.ToString();
            Speed = xDoc.SelectSingleNode("rss/channel/yweather:wind", man).Attributes["speed"].Value.ToString();
            Pressure = xDoc.SelectSingleNode("rss/channel/yweather:atmosphere", man).Attributes["pressure"].Value.ToString();
            Sunrise = xDoc.SelectSingleNode("rss/channel/yweather:astronomy", man).Attributes["sunrise"].Value.ToString();
            Sunset = xDoc.SelectSingleNode("rss/channel/yweather:astronomy", man).Attributes["sunset"].Value.ToString();
            Temp = xDoc.SelectSingleNode("rss/channel/item/yweather:condition", man).Attributes["temp"].Value.ToString();
            Code = xDoc.SelectSingleNode("rss/channel/item/yweather:condition", man).Attributes["code"].Value.ToString();
            ImageUrl = string.Format("resx://MediaBrowser/MediaBrowser.Resources/_{0}", this.Code);
            //this.ImageUrl = string.Format("http://l.yimg.com/a/i/us/we/52/{0}.gif", this.Code);
            LongTemp = string.Format("{0}°{1} {2}", Temp, Unit, CodeDescription);
            LongPressure = string.Format("{0} {1}", Pressure, PressureUnit);
            LongWindSpeed = string.Format("{0} {1} {2}", Speed, SpeedUnit, Direction);
            LongVisibility = string.Format("{0} {1}", VisibileDistance, DistanceUnit);

            var tempForecast = xDoc.SelectNodes("rss/channel/item/yweather:forecast", man);
            //<yweather:forecast day="Fri" date="24 Apr 2009" low="50" high="63" text="Partly Cloudy" code="30" />
            foreach (XmlNode temp in tempForecast)
            {
                var fi = new ForecastItem();
                fi.Day = temp.Attributes["day"].Value.ToString();
                fi.Date = temp.Attributes["date"].Value.ToString();
                fi.Low = temp.Attributes["low"].Value.ToString();
                fi.High = temp.Attributes["high"].Value.ToString();
                fi.Code = temp.Attributes["code"].Value.ToString();
                fi.CodeDescription = temp.Attributes["text"].Value.ToString();
                fi.ImageUrl = string.Format("resx://MediaBrowser/MediaBrowser.Resources/_{0}", fi.Code);
                if (_forecast.Count < 2)
                {
                    _forecast.Add(fi);
                }
                _extendedForecast.Add(fi);
            }
        }
Esempio n. 4
0
        private void ParseYahooWeatherDoc(XmlDocument xDoc)
        {
            //Setting up NSManager
            XmlNamespaceManager man = new XmlNamespaceManager(xDoc.NameTable);
            man.AddNamespace("yweather", "http://xml.weather.yahoo.com/ns/rss/1.0");

            this.Unit = xDoc.SelectSingleNode("rss/channel/yweather:units", man).Attributes["temperature"].Value.ToString();
            this.CodeDescription = xDoc.SelectSingleNode("rss/channel/item/yweather:condition", man).Attributes["text"].Value.ToString();
            this.Location = xDoc.SelectSingleNode("rss/channel/yweather:location", man).Attributes["city"].Value.ToString();
            this.Temp = xDoc.SelectSingleNode("rss/channel/item/yweather:condition", man).Attributes["temp"].Value.ToString();
            this.Code = xDoc.SelectSingleNode("rss/channel/item/yweather:condition", man).Attributes["code"].Value.ToString();
            this.ImageUrl = string.Format("resx://MediaBrowser/MediaBrowser.Resources/_{0}", this.Code);
            //this.ImageUrl = string.Format("http://l.yimg.com/a/i/us/we/52/{0}.gif", this.Code);
            this.LongTemp = string.Format("{0}°{1} {2}", Temp, Unit, CodeDescription);

            var tempForecast = xDoc.SelectNodes("rss/channel/item/yweather:forecast", man);
            //<yweather:forecast day="Fri" date="24 Apr 2009" low="50" high="63" text="Partly Cloudy" code="30" />
            foreach (XmlNode temp in tempForecast)
            {
                ForecastItem fi = new ForecastItem();
                fi.Day = temp.Attributes["day"].Value.ToString();
                fi.Date = temp.Attributes["date"].Value.ToString();
                fi.Low = temp.Attributes["low"].Value.ToString();
                fi.High = temp.Attributes["high"].Value.ToString();
                fi.Code = temp.Attributes["code"].Value.ToString();
                fi.CodeDescription = temp.Attributes["text"].Value.ToString();
                fi.ImageUrl = string.Format("resx://MediaBrowser/MediaBrowser.Resources/_{0}", fi.Code);
                _forecast.Add(fi);
            }
        }