Objective is to extract the entire contents of the rules element as is while taking account that the rules element may or may not contains child elements several levels deep
If you just want the entirety of the
rules element as a string (rather than caring about its contents as xml), you don't need to dig into its contents, you just need to get the element as an
XNode and then call ToString() on it :
The following example uses this method to retrieve indented XML.
XElement xmlTree = new XElement("Root", new XElement("Child1", 1) ); Console.WriteLine(xmlTree);
This example produces the following output:
<Root> <Child1>1</Child1> </Root>
if you want to prevent duplicates than you will need to use Distinct() or GroupBy() after parsing the xml and before building the string.
I'm still not fully understanding exactly what the output should be, so I can't provide a clear solution on what exactly to use, or how, in terms of locating duplicates. If you can refine the original post that would help.
- we need the structure of the xml as it would appear in your scenario. nesting and all.
- we need an example of the final string. saving it to a db doesn't really matter for this post so you only need to briefly mention that once, if at all.
- Linq duplicate elements when iterating over XML
- C# foreach doesn't modify properties of elements when iterating over collection created by linq .Select()
- How to query an XDocument with LINQ when elements have a colon in their name?
- How do you handle arbitrary namespaces when querying over Linq to XML?
- I am wondering about the state of connection and impact on code performance by 'yield' while iterating over data reader object
- Why am I able to edit a LINQ list while iterating over it?
- Duplicate Rows when Data Binding with LINQ to Entities
- When to prefer joins expressed with SelectMany() over joins expressed with the join keyword in Linq
- How to understand the following C# linq code of implementing the algorithm to return all combinations of k elements from n
- How to reuse a linq expression for 'Where' when using multiple source tables
- Avoiding code repetition when using LINQ
- Iterating over class properties using LINQ
- LINQ Source Code Available
- Duplicate rows when using orderby, Skip() and Take() with LINQ
- A clever alternative in LINQ for iterating over HashSet<string>
- Merge duplicate data without affecting others in LINQ code
- Strange slowness while iterating over Linq result
- LINQ query returns old results when source list is re-initialized
- Iterating over LINQ entity results
- creating Linq to sqlite dbml from DbLinq source code
- Duplicate elements when adding XElement to XDocument
- C# - Code supposed to be unreachable when calculate value in LINQ sum method
- Linq sub query when using a repository pattern with EF code first
- When should I convert a loop over collection to Linq statement?
- Early return when an Enumerable has more then X elements in Linq
- Avoiding duplicate code in Linq Select method
- Preventing duplicate element access when reading an XML using LINQ
- why does this linq code get exponentially slower when applying First() to projection?
- Will iterating over Linq Lookup make a db query for each iteration
- Getting 'Data source is an invalid type' when binding Linq query to Gridview
- How can I add OrderBy to this LINQ statement?
- Linq query on ISet collection
- Read xml data with namespaces from SQLite database in C#
- How to Convert SQL query to LINQ (to get last record each bookingStatus)
- Slickest way to put objects into separate lists based on a property value
- datatable replace zero with null or empty string via linq
- Iterate through the properties of a lambda expression?
- mapping from many-to-one in entity framework Core
- Using Linq comparision with previous record
- Intersection of two sets (Lists) of data
- Get Query optimization in ef-core and Linq
- Kendo Grid C# - Select current page without refresh datasource again
- How can I return all the columns of a table using multiple distinct columns in Linq
- work with ICollection and IEnumerable<T>
- How to convert an IQueryable<T> to a List<T>?
- Get a list made up of a list of grouped items from a source list
- LINQ provider to a Web API causing lots of grief
- How to get the top 3 elements in an int array using LINQ?
- LINQ CopyToDataTable -- Cannot cast DBNull.Value to type 'System.Decimal'. Please use a nullable type
- How can define multiple KEY in EntityFrameWorkClass C#