score:3

Accepted answer
var document = XDocument.Parse(xml);

var bookElements = document.Descendants("book")
    .Where(arg => arg.Element("author").Element("first-name").Value == "Benjamin")
    .ToList();

or

var bookElements = document.Descendants("first-name")
    .Where(arg => arg.Value == "Benjamin")
    .Select(arg => arg.Parent.Parent)
    .ToList();

[Edit] As you keep editing the question, I will edit the answer :).

To find the first book that meets the criteria:

var foundBookElement = document.Descendants("book")
    .Where(arg => arg.Element("author").Element("first-name").Value == "Benjamin")
    .FirstOrDefault();

foundBookElement will be null if none of the books match the criteria.


Related Articles