我正在对XDocument
进行以下查询。最后一级.Descendants("Instance")
生成一个表单的XElements列表:
<Instance>filepath1</Instance>
<Instance>filepath2</Instance>
<Instance>filepath3</Instance>
<Instance>filepath4</Instance>
查询
List<string> fileNames = xDoc.Descendants("Main")
.FirstOrDefault()
.Descendants("SecondLevel")
.FirstOrDefault()
.Descendants("Instance")
.Select().ToList(); //this line is not correct. Need to get the instances node values as List<string>
如何将值filepath1
,filepath2
..存储在List<string>
?
答案 0 :(得分:6)
使用
....
.Descendants("Instance")
.Select(e => e.Value) // project to the string values
.ToList();