我被XDocument再次拋錨了。我試圖提取溫度元件(12在本例中)的值時,類屬性具有值=「高」(和「低」)一個屬性等於一個特定值的元素的提取值
我的XML的一個子集:
<forecastGroup>
<forecast>
<temperatures>
<textSummary>Low plus 2. High 12.</textSummary>
<temperature unitType="metric" units="C" class="high">12</temperature>
<temperature unitType="metric" units="C" class="low">2</temperature>
</temperatures>
</forecast>
...etc.
<forecast>
<temperature unitType="metric" units="C" class="high">15</temperature>
<temperature unitType="metric" units="C" class="low">3</temperature>
</forecast>
<forecastGroup>
到目前爲止的代碼:
XDocument loaded = XDocument.Parse(strInputXML);
foreach (var forecast in loaded.Descendants("forecastGroup").Elements("forecast"))
{
//existing code doing stuff here using the XDocument loaded
High = "this is where I'm lost";
}
我貌似試過的嘗試,選擇每一個元素的組合,屬性和子孫」,但我在虧損
如果你願意,'XPath'會更容易。 – Marc