Search code examples
c#windows-phone-7.1.1

How do you get the descendant elements from this xml file?


xml:

http://wsf.cdyne.com/WeatherWS/Weather.asmx/GetCityWeatherByZIP?ZIP=48183

Here is my code:

    private void GetWeather()
    {
        WebClient web = new WebClient();
        web.DownloadStringCompleted += new DownloadStringCompletedEventHandler(web_DownloadStringCompleted);
        string uriAddr = "http://wsf.cdyne.com/WeatherWS/Weather.asmx/GetCityWeatherByZIP?ZIP=48183";
        web.DownloadStringAsync(new Uri(uriAddr));
    }
    void web_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
    {
        if (e.Error != null)
        {
            MessageBox.Show("error");

        }

        XElement XmlWeather = XElement.Parse(e.Result);

        foreach (var item in XmlWeather.Descendants("WeatherReturn"))
        {
            // code to get element info
        }

    }

I cannot even get inside the foreach statement. Any suggestions?


Solution

  • You need to include the namespace:

    XNamespace ns = "http://ws.cdyne.com/WeatherWS/";
    

    You can then call XmlWeather.Descendants(ns + "WeatherReturn")