I have the following XML
<?xml version="1.0" encoding="utf-8"?>
<Applications xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<Blocks>
<Block Name="block1">
<Attributes>
<Tag>Attribute1</Tag>
<Layer>layer1</Layer>
</Attributes>
<Attributes>
<Tag>Attribute2</Tag>
<Layer>layer2</Layer>
</Attributes>
</Block>
<Block Name="block2">
<Attributes>
<Tag>Attribute1</Tag>
<Layer>layer0</Layer>
</Attributes>
</Block>
</Blocks>
</Applications>
I would like to use a linq statement to catch all the details and populate a List with the following class. i.e. List
public class Block
{
public string Tag { get; set; }
public string Layer { get; set; }
}
I've tried...
List<Block> data =
(from a in xdoc.Root.Elements("Blocks")
where (string)a.Attribute("Name") == "block1"
select new Block
{
Tag = (string)a.Element("Tag"),
Layer = (string)a.Element("Layer")
}).ToList();
Can you see where I'm going wrong, little new to linq.