次のようなxmlファイルがあります
<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>
以下を使用しても、 current_condition と weather からデータを取得できます。
var fiveDayForcastDayTwo = _test("washington, tyne and wear").Skip(1).First();
27日に帰ります
var fiveDayForcastDayTwo = _test("washington, tyne and wear").Skip(2).First();
28日などに戻ります
私が抱えている問題は毎時です。次の日にスキップしながら、毎時ノードをループして時間 0 と時間 6 などのデータを取得するにはどうすればよいですか。
ジョージに助けていただければ幸いです
cs ファイルのコード
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();
}