我被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