Parsing XDocument Using LINQ

I am making the following request on an XDocument . The last level .Descendants("Instance") gives a list of XElements of the form:

 <Instance>filepath1</Instance> <Instance>filepath2</Instance> <Instance>filepath3</Instance> <Instance>filepath4</Instance> 

Request

  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> 

How to save the values โ€‹โ€‹of filepath1 , filepath2 .. in List<string> ?

+4
source share
1 answer

Using

  .... .Descendants("Instance") .Select(e => e.Value) // project to the string values .ToList(); 
+6
source

Source: https://habr.com/ru/post/1399973/


All Articles