var document = XDocument.Parse(xml); var bookElements = document.Descendants("book") .Where(arg => arg.Element("author").Element("first-name").Value == "Benjamin") .ToList();
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.
- Getting the previous node of a searched keyword in xml
- How to take value based on previous node from the given xml file
- LINQ request for getting the furthest xml child node with an attribute
- Code equivalent to the 'let' keyword in chained LINQ extension method calls
- How do I get the value from a specific node in an XML file?
- C# Linq to XML getting the elements where value of name contains a specific string
- Remove XML node if the inner tag matches value using Linq in C#
- Retrieve the node values from XML file in LINQ and C#
- Getting an XML node using LINQ
- WP7 Getting and storing data from an xml web service for use across the project
- Getting error while Parsing the XML data
- Getting "Could not find an implementation of the query pattern for source type 'ExcelQueryable<T>'. " Error
- Getting the Parent object in nested XML to Linq
- LINQ, Getting the next and previous record in my table (I'm Confused)
- How to access the properties on a XML Node via linq?
- Search all child nodes of XML node for a value and remove the grandparent node
- How to filter on a xml node name keeping the tree structure?
- I need to save the XML file using linq with xml code in C#
- How to see a record that has a key that matches the previous records key in XML using LinQ to XML?
- How to copy a node xml and appended to the specified node using linq to XML
- Read Particular XML Node (values, not just InnerText) AND put the values in TextBox
- Read all the values in a node in xml with key value pairand print them in seperate line in
- I want to display the first node XML attribute on form?
- Only getting the first value while parsing an XML document using Linq
- Getting XML node based on text value, that ends with XML
- Compare XML Node Values using Name Tag and Remove the Tag
- XML parsing using LINQ: what is the best way to get value of nearby node
- Getting all attribute values from node by specifying the ancestor node using LINQ
- I want to fetch the data of child node from XML using C# Linq
- Getting the root element of xml file in linq
More Query from same tag
- The property is not a navigation property of entity type
- Using LINQ to SQL where database tables can have extra columns
- Linq query With Sub Query, Count, Max, Sum, left join whith extended on
- Linq2Sql -> Searching the database against a local collection of values - "Queries with local collections are not supported"
- LINQ get objects by date interval
- Get Average Using LINQ
- GroupBy Select with String.Join
- using linq query to find value that differs from previously found value
- c# to vb.net linq select
- Overloading Linq Except to allow custom struct with byte array
- Change datagrid selected item using two comboboxes
- Safely dereferencing FirstOrDefault call in Linq c#
- How To Write Distance LINQ query i have Lat, Long in table with varchar type SQL Server
- Create where clause with column name only known at runtime
- Update a value by jQuery
- Equivalent of LINQ let clause in SQL Server
- LINQ - database query using "into", how do I reference data prior to "into" in the select clause?
- Optimizing a slow LINQ query
- Adding a linked object to another object in C# ASP.Net MVC
- Using LINQ to count value frequency and display in MVC View
- Linq selecting on string value "not equals" ignores DB nulls
- Nested GroupBy extension method in LINQ
- How to C# linq GroupBy multiple arrays with array values
- How to sort children of an element in XmlDocument in C#?
- LINQ to SQL C# COALESCE
- EntitySet.Last() is not the latest added element?
- Convert string to linq query
- How can I apply sorting on navigational (child) properties?
- Combine two list<> and remove the duplicates in it
- Linq Select All Except items from listbox