我正在更新我的一些舊代碼,並決定將所有從XPath相關的XML更改爲Linq(所以請同時學習linq)。我遇到了這個代碼,有人可以告訴我如何將其轉換爲linq語句?從`XPathNodeIterator`轉換爲`linq`
var groups = new List<string>();
XPathNodeIterator it = nav.Select("/Document//Tests/Test[Type='Failure']/Groups/Group/Name");
foreach (XPathNavigator group in it)
{
groups.Add(group.Value);
}
'XDocument xDoc = XDocument.Parse(...);''var groups = xDoc.Descendants(「Name」)。Select(n => n.Value).ToList();' – 2012-07-16 08:26:39