LINQ2XML クエリが目標の半分まで機能しています。
var XMLDoc = XDocument.Load("WeatherData.xml");
var maximums = from tempvalue in
XMLDoc.Descendants("temperature").Elements("value")
where tempvalue.Parent.Attribute("type").Value == "maximum"
select (string)tempvalue;
var minimums = from tempvalue in
XMLDoc.Descendants("temperature").Elements("value")
where tempvalue.Parent.Attribute("type").Value == "minimum"
select (string)tempvalue;
List<string> MaxTemps = maximums.ToList();
List<string> MinTemps = minimums.ToList();
ただし、レイアウト キー情報 (XML コメントを参照) を一致させる必要があるため、XML ドキュメントから時間情報を取得するのに問題があり、これに参加するための LINQ での最適なソリューションは何かと考えています。既存のクエリを使用した時間データ:
(ちなみに、この XML データは Web サービスからのものです)
<?xml version="1.0" encoding="utf-8"?>
<dwml>
<data>
<time-layout>
<!-- Maximums Key -->
<layout-key>k-p24h-n7-1</layout-key>
<start-valid-time>2009-02-09T07:00:00-05:00</start-valid-time>
<end-valid-time>2009-02-09T19:00:00-05:00</end-valid-time>
<start-valid-time>2009-02-10T07:00:00-05:00</start-valid-time>
<end-valid-time>2009-02-10T19:00:00-05:00</end-valid-time>
<start-valid-time>2009-02-11T07:00:00-05:00</start-valid-time>
<end-valid-time>2009-02-11T19:00:00-05:00</end-valid-time>
<start-valid-time>2009-02-12T07:00:00-05:00</start-valid-time>
<end-valid-time>2009-02-12T19:00:00-05:00</end-valid-time>
<start-valid-time>2009-02-13T07:00:00-05:00</start-valid-time>
<end-valid-time>2009-02-13T19:00:00-05:00</end-valid-time>
<start-valid-time>2009-02-14T07:00:00-05:00</start-valid-time>
<end-valid-time>2009-02-14T19:00:00-05:00</end-valid-time>
<start-valid-time>2009-02-15T07:00:00-05:00</start-valid-time>
<end-valid-time>2009-02-15T19:00:00-05:00</end-valid-time>
</time-layout>
<time-layout>
<!-- Minimums Key -->
<layout-key>k-p24h-n7-2</layout-key>
<start-valid-time>2009-02-08T19:00:00-05:00</start-valid-time>
<end-valid-time>2009-02-09T08:00:00-05:00</end-valid-time>
<start-valid-time>2009-02-09T19:00:00-05:00</start-valid-time>
<end-valid-time>2009-02-10T08:00:00-05:00</end-valid-time>
<start-valid-time>2009-02-10T19:00:00-05:00</start-valid-time>
<end-valid-time>2009-02-11T08:00:00-05:00</end-valid-time>
<start-valid-time>2009-02-11T19:00:00-05:00</start-valid-time>
<end-valid-time>2009-02-12T08:00:00-05:00</end-valid-time>
<start-valid-time>2009-02-12T19:00:00-05:00</start-valid-time>
<end-valid-time>2009-02-13T08:00:00-05:00</end-valid-time>
<start-valid-time>2009-02-13T19:00:00-05:00</start-valid-time>
<end-valid-time>2009-02-14T08:00:00-05:00</end-valid-time>
<start-valid-time>2009-02-14T19:00:00-05:00</start-valid-time>
<end-valid-time>2009-02-15T08:00:00-05:00</end-valid-time>
</time-layout>
<parameters>
<!-- 1st Key -->
<temperature type="maximum" time-layout="k-p24h-n7-1">
<value>44</value>
<value>57</value>
<value>55</value>
<value>40</value>
<value>39</value>
<value>34</value>
<value>33</value>
</temperature>
<!-- 2nd Key -->
<temperature type="minimum" time-layout="k-p24h-n7-2">
<value>24</value>
<value>38</value>
<value>46</value>
<value>35</value>
<value>25</value>
<value>27</value>
<value>23</value>
</temperature>
</parameters>
</data>
</dwml>