Linq newbie here. Did the searching, and couldn't find an exact question; tried to work from other answers that were similar, but still couldn't get it.
Having trouble returning all instances of a particular element name. I can get one item returned, just not them all.
Here is the XML:
<?xml version="1.0"?>
<printerlist>
<list type="aff">
<printserver>print-server1</printserver>
<printserver>print-server2</printserver>
<printserver>print-server3</printserver>
</list>
<list type="lff">
<printserver>print-sever4</printserver>
<additionalprinters>
<printer>
<fullname>\\serverb\bbb</fullname>
</printer>
<printer>
<fullname>\\serverc\aaa</fullname>
</printer>
</additionalprinters>
</list>
</printerlist>
And here is the code to try and get the list:
var query = from c in xml.Root.Descendants("list")
where (string)c.Attribute("type") == "aff"
select c.Element("printserver");
foreach (string name in query)
{
Console.WriteLine("Server Name: {0}", name);
}
This only produces the first element of printserver: print-server1 How can I get the foreach to list all 3 servers that are in the aff list?
Thanks