I have XML with the following structure:
<?xml version="1.0" encoding="UTF-8"?>
<pessoas>
<pessoa>
<nome>Joao</nome>
<email>[email protected]</email>
</pessoa>
</pessoas>
And I'm trying to get the contents of the tag with the following query of LINQ type:
static void Main(string[] args)
{
XElement root = XElement.Load("Pessoa.xml");
List<string> nomes = root.Elements("pessoas").Elements("pessoa").Select(x => (string)x.Element("nome")).ToList();
foreach (var n in nomes) Console.WriteLine(n);
Console.WriteLine(nomes.Count);
Console.ReadKey();
}
It should display as the output Joao
but nothing is displayed on the console and the amount of items returned by the search is 0.
I would like to know how I could get the contents of the tag through a query in LINQ?