I have xml:
Ray
Other
When using Elements()
you have to specify the structure more precisely.
In your code, cover
is a <book>
element. But size
is an attribute of <cover>
.
var c = from cover in xml.Elements("book")
where (string)cover.Attribute("size").Value == "mini"
select cover.Value;
This ought to work:
var c = from cover in xml.Elements("book")
.Elements("cover")
where (string)cover.Attribute("size").Value == "mini"
select cover.Value;
Xpath can simplify your code
var covers = xDoc.XPathSelectElements("//cover[@size='mini']").ToList();
to get the inner text
var covers = xDoc.XPathSelectElements("//cover[@size='mini']")
.Select(x => x.Value)
.ToList();