Q:

XML loop through sub data

I have an xml file like the following
<data>
  <request>
    <type></type>
    <query></query>
  </request>
  <current_condition></current_condition>
  <weather>
    <date>26-12-2012</date>
    <astronomy>
      <sunrise></sunrise>
    </astronomy>
    <maxtempC/>
    <maxtempF/>
    <hourly>
      <time>0</time>
      <tempC>4</tempC>
      <tempF>39</tempF>
      <windspeedMiles>17</windspeedMiles>
    </hourly>
    <hourly>
      <time>6</time>
      <tempC>4</tempC>
      <tempF>39</tempF>
      <windspeedMiles>17</windspeedMiles>
    </hourly>
    <hourly>
      <time>12</time>
      <tempC>4</tempC>
      <tempF>39</tempF>
      <windspeedMiles>17</windspeedMiles>
    </hourly>
    <hourly>
      <time>18</time>
      <tempC>4</tempC>
      <tempF>39</tempF>
      <windspeedMiles>17</windspeedMiles>
    </hourly>
  </weather>
  <weather>
    <date>27-12-2012</date>
    <astronomy>
      <sunrise></sunrise>
    </astronomy>
    <maxtempC/>
    <maxtempF/>
    <hourly>
      <time>0</time>
      <tempC>4</tempC>
      <tempF>39</tempF>
      <windspeedMiles>17</windspeedMiles>
    </hourly>
    <hourly>
      <time>6</time>
      <tempC>4</tempC>
      <tempF>39</tempF>
      <windspeedMiles>17</windspeedMiles>
    </hourly>
    <hourly>
      <time>12</time>
      <tempC>4</tempC>
      <tempF>39</tempF>
      <windspeedMiles>17</windspeedMiles>
    </hourly>
    <hourly>
      <time>18</time>
      <tempC>4</tempC>
      <tempF>39</tempF>
      <windspeedMiles>17</windspeedMiles>
    </hourly>
  </weather>
</data>

I can get the data from current_condition and weather, even when i use the following:
var fiveDayForcastDayTwo = _test("washington, tyne and wear").Skip(1).First(); will return 27th
var fiveDayForcastDayTwo = _test("washington, tyne and wear").Skip(2).First(); will return 28th etc
Problem I am having is with hourly, how can i loop through the hourly nodes and get the data for time 0 and time 6 etc, while also skipping to the next day.
Any help would be appreciated
George
Code for cs file
public IEnumerable<DisplayWeatherConditions> DisplayFiveDayForcast(string id)
{
        XDocument doc = XDocument.Load(string.Format("http://www.worldweatheronline.com/feed/premium-weather-v2.ashx?key={0}&feedkey={1}&format=xml&q={2}&tp=6", 
                                       sPartnerID, sLicenseKey, HttpUtility.UrlEncode(id)));

        var displayFiveDayForcast = from wd in doc.Descendants("weather")
                  select new DisplayWeatherConditions()
                  {
                      date          = (string)wd.Element("date") ?? "NA",
                      sunRise       = (string)wd.Element("astronomy").Element("sunrise") ?? "NA",
                      sunSet        = (string)wd.Element("astronomy").Element("sunset") ?? "NA",
                      maxtempC      = (string)wd.Element("maxtempC") ?? "NA",
                      maxtempF      = (string)wd.Element("maxtempF") ?? "NA",
                      mintempC      = (string)wd.Element("mintempC") ?? "NA",
                      mintempF      = (string)wd.Element("mintempF") ?? "NA",
                      hourlyTempC   = (string)wd.Element("hourly")?? "NA",
                  };
        return displayFiveDayForcast.AsEnumerable();
}

A:

I was able to get the values you requested from the (fixed) XML data you provided by using the following (note that I am using an anonymous type to collect the values).
XDocument doc = XDocument.Load([your source document]);
var v1 = doc.Descendants("weather");
var v3 = v1.Where(e => e.Element("date").Value == "26-12-2012");
var v2 = v3.Elements("hourly")
    .Select(e =>
        new
        {
            hour = e.Element("time").Value,
            tempC = e.Element("tempC").Value,
            tempF = e.Element("tempF").Value,
            wind = e.Element("windspeedMiles").Value
        });

Or in the context of the code you already have:
...
hourlyTempC   = wd.Descendants("hourly").Select(e =>
                    new
                    {
                        hour = e.Element("time").Value,
                        tempC = e.Element("tempC").Value,
                        tempF = e.Element("tempF").Value,
                        wind = e.Element("windspeedMiles").Value
                    })
...

Your provided code is casting the resulting first element hourly to a string - but since you have multiple hourly elements you need a structure that can handle that (like an IEnumerable) - which is exactly what is returned by Select.

