score:1
Accepted answer
var query =
from xe in doc.element("taxdata").elements("table")
from gr in xe.elements("row").groupby(_ => _.attribute("locid").value)
select new
{
id = xe.attribute("id").value,
locid = gr.key,
rows = gr.count(),
};
score:0
var xe = doc.descendants("table")
.elements("row")
.groupby(a => a.attribute("locid").value)
.select(a => new { value = a.key, count = a.count() });
score:2
string[] tableids = doc.descendants("table").select(t => t.attribute("id").value).toarray<string>();
foreach (var id in tableids)
{
var rowgroups = doc.descendants("table").elements()
.where(row => row.parent.attribute("id").value.equals(id))
.groupby(row => row.attribute("locid").value)
.select(row => row);
// ... do something ...
// here you will have all the grouped xelements in rowgroups
}
Source: stackoverflow.com
Related Query
- Grouping of Xml Elements using Linq
- How to get elements by name in XML using LINQ
- Selecting elements from XML file using LINQ
- Querying xml child elements with prefixed namespace using LINQ to XML
- Selecting all XML elements and their values dynamically using LINQ
- Select descendent nodes and elements from an XML using LINQ
- Grouping List elements and map to new model using Linq
- Grouping a list of objects by parent using linq to output child elements
- Read the XML using Linq and check if the elements exist
- Parsing XML with pairs of elements using XDocument and LINQ
- How to get multiple elements by name in XML using LINQ
- How to concatenate all child elements with same names values using LINQ to XML
- XML elements to Tuple using LINQ in C#
- XML compare Elements and Values using LINQ to XML
- Removing XML elements using LINQ
- Find list of xml elements that have a list of names using linq (and remove them)
- Remove two elements in XML using linq
- Get Attribute Values using LINQ to XML with Unknown Elements
- Querying an Xml Document for elements using Linq
- C# Reading multiple elements with same name using LINQ to XML
- Construct a list of wpf Hyperlink elements from an XML source file using Linq
- Accessing xml elements using LINQ to XML
- Check for missing elements while using LINQ to XML
- using LINQ to search in 2 different elements in XML file
- How to load XML Elements using LINQ from XDocument into a class (not using Descendants)
- Accessing XML elements with LINQ using VB.net (not C#)
- how to take desired value from the multiple same elements in the xml by using LInq c#
- How can I select specific elements from an XML using Linq to Xml?
- trouble getting attributes from XML elements using LINQ
- Using LINQ to pull XML elements
More Query from same tag
- C# Cannot access child value on Newtonsoft.Json.Linq.JProperty
- Rookie thing: How to collect data from multiple tables most deftly?
- Linq to Entities with custom method in Where
- sql to linq where statement with case
- Parsing xml using XDocument - Deserialization
- Data Conflict in LINQ
- Simplifying a foreach and Any() with only Linq
- How to group by a given column in a List of T collection using linq?
- Translating between LINQ formats
- LINQ equivalent of my SQL Query for UNION ALL
- How can I return a object with the sum of all objects from a list using Linq?
- Linq to SQL - how to dynamically filter by columns not in select
- How do I write a Linq query that needs a subquery?
- C#/LINQ: How to Query this XML Structure
- Why dose the tiny performance boost happen when I reuse the Linq query variable?
- can i use linq syntax for filteting the datatable
- Linq performance: Any vs. Contains
- jQuery like Linq?
- Acces data from objects in a list
- LinQ Item Present Validation
- How to GroupBy/GroupJoin XElements using LINQ
- "An EdmType cannot be mapped to CLR classes multiple times" when called via LINQ Expressions. Guessing EDMX is loaded twice
- OData - converting parameter entity set to LINQ
- Sort by frequency and value using LINQ
- JSON.NET: Flattening a JArray to JObjects within Linq Query
- How do I best combine these two LINQ expressions?
- Sort or Order a List of strings containing a specific word with LINQ
- "LINQ to Entities does not recognize the method" when Convert to Int 32
- How to put a self join with LINQ on XDocument?
- How to merge duplicate rows (Based on column) of data table & put it in separate data table?