There are various things wrong with your current code:
- You're using
Attribute
when there aren't attributes in the XML - You're trying to use the
Value
property onDescendants
, butDescendants
returnsIEnumerable<XElement>
- You're not using
lv2
anywhere - You're looking for
level1
as an element name rather thanLevel1
. (XML is case-sensitive.)
I suspect you just want:
var doc = XDocument.Load(filename);
var values = from level in doc.Descendants("Level1").Descendants("Level2")
select new {
Value1 = (string) level.Element("Value1"),
Value2 = (string) level.Element("Value2"),
Value3 = (string) level.Element("Value3"),
Value4 = (string) level.Element("Value4")
};