score:1
Accepted answer
public instructionsequence getsequencefromsource(xdocument urisource)
{
return this.getsequencefromsource(urisource.root);
}
public instructionsequence getsequencefromsource(xelement step)
{
return new instructionsequence
{
step = step.element("position") == null ? 0 : (int)step.element("position"),
sequence = step.element("sequence")?.elements("step").select(s => this.getsequencefromsource(s)).tolist(),
};
}
score:0
func<xelement, instructionsequence> getchildcontents = child => new instructionsequence { step = convert.toint32(child.element("position").value), sequence = null };
var matchitems = new list<instructionsequence>();
var splitgroups = doc.root
.descendants("step")
.groupby(v => (v.firstnode is xelement) && (((xelement)v.firstnode).name != "sequence"));
var matchgroup = splitgroups.single(e => e.key == true);
var remaining = splitgroups.single(e => e.key == false);
matchitems.addrange(matchgroup.select(getchildcontents));
matchitems.addrange(remaining.descendants("sequence").descendants("step").select(getchildcontents));
Source: stackoverflow.com
Related Query
- LINQ to XML issue with converting a tree to a list
- Issue with checking nullable xml values when converting to linq
- Trying to parse XML tree with Linq to XML (C#)
- Converting list with nested list to a separate list using Linq
- Issue With LINQ and Reference List
- Converting LINQ to XML result to generic list in VB.NET. Odd error
- LINQ to XML - list of custom objects with attributes from parent
- Issue with converting XML document to string array
- Fill dropdown list from xml with linq
- Building an object list with Linq to Xml
- Linq OrderBy issue when converting string to int with space
- Issue with converting IEnumerable to List
- c# linq to xml XElement group by ancestor attribute to create list of entities collection with key
- Issue with LINQ inside XML Literals when generating XSD
- Issue with querying database using LINQ query to bring list of DTO
- List is empty after parsing XML with LinQ
- Linq to XML (C#) parse XML tree with no attributes/id to object
- Issue with LINQ to XML
- Converting a Linq expression tree that relies on SqlMethods.Like() for use with the Entity Framework
- Create a tree structure in linq with a single list source with parent - child as strings of an object
- list all tags in XML with LINQ
- Load list with linq to xml
- Issue with Linq query syntax. Cannot convert to list
- Remove item from xml list with Linq
- Change XML structure with Linq and having a foreach issue
- Querying XML tree with Linq
- Parsing XML With LINQ Issue
- Using a filter list with linq to xml
- LINQ to xml query with performance issue
- C# Converting List to Enumerable and Selecting With LINQ
More Query from same tag
- Get ID from association using Entity Framework
- How can I use a LINQ projection with List<MyStructure> to get a NameValueCollection?
- Querying the nested xml using linq by specifying attribute value
- looking for a better way to get a count-per-city
- Strangest LINQ to SQL case I have ever seen
- Inject arguments in LINQ queries
- How to call a function or property in a LINQ Query Provider (ExpressionVisitor)
- How to parse XML file in C# using LINQ?
- LINQ - Searching one to many for exact match of array
- Get List entries of a specific subtype using LINQ
- How to convert Linq.ParallelQuery to Linq.IQueryable
- Performance of LINQ Any vs FirstOrDefault != null
- Missing schema in DBML if using LINQ to SP and Sp returning multiple record sets
- Map list of children to parent object from join table with LINQ
- Update one column and set all values to 1 using Entity Framework
- Hierarchical select in Entity Framework with lambda expression
- Why am I required to reference System.Numerics with this simple LINQ expression?
- Eager-loading using LINQ to SQL with Include()
- Querying SQL table with LINQ and XElement
- In place algorithm for string transformation
- Is there a Javascript equivalent of Array.prototype.find() that works on older browsers?
- Find row via As Of date in a DataTable
- Can a conditional LINQ query be combined into one that runs every time?
- Unable to parse xml string using Xdocument and Linq
- AsDataView Does Not Show Up
- LINQ Except using custom Comparer
- Find an attribute that contains a ceratin string and modifying its Value in c# using LINQ
- Get and Add/Update multilevel embedded/nested MongoDB document using C#
- Performance improvement for Lambda using Array.Contains?
- Simplify the following algorithm