使用LINQ解析XDocument

Nem*_*emo 4 c# xml linq

我正在进行以下查询XDocument.最后一级.Descendants("Instance")产生一个表单的XElements列表:

<Instance>filepath1</Instance>
<Instance>filepath2</Instance>
<Instance>filepath3</Instance>
<Instance>filepath4</Instance>
Run Code Online (Sandbox Code Playgroud)

询问

 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>
Run Code Online (Sandbox Code Playgroud)

我怎么能存储的值filepath1,filepath2..在List<string>

Hen*_*man 6

通过使用

 ....
  .Descendants("Instance")
  .Select(e => e.Value) // project to the string values
  .ToList();
Run Code Online (Sandbox Code Playgroud)