score:3
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>
score:0
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.
Source: stackoverflow.com
Related Query
- Linq duplicate elements when iterating over XML
- C# foreach doesn't modify properties of elements when iterating over collection created by linq .Select()
- Preventing duplicate element access when reading an XML using LINQ
- Last node is not being return when iterating from Xelement List using Linq to XML in C#
- C# parsing xml document with LINQ where there are varying number of duplicate elements
- Construct a list of wpf Hyperlink elements from an XML source file using Linq
- Accessing nested elements while iterating an XML LINQ query?
- LINQ query to get XML elements when an attribute is not present
- 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?
- How to remove an element from an xml using Xdocument when we have multiple elements with same name but different attributes
- I am wondering about the state of connection and impact on code performance by 'yield' while iterating over data reader object
- How to get elements by name in XML using LINQ
- 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
- Parse XML with LINQ to get child elements
- Avoiding code repetition when using LINQ
- Iterating over class properties using LINQ
- How do I preserve whitespace characters when parsing XML from C# LINQ
- How do you remove xmlns from elements when generating XML with LINQ?
- LINQ Source Code Available
- Duplicate rows when using orderby, Skip() and Take() with LINQ
- How to check if XML contains element when using LINQ to XML?
- A clever alternative in LINQ for iterating over HashSet<string>
- XML to LINQ with Checking Null Elements
- Selecting elements from XML file using LINQ
- Querying xml child elements with prefixed namespace using LINQ to XML
More Query from same tag
- Entity Framework (5) View parameters passed to generated SQL
- LINQ .Where query takes 5+ minutes to execute
- Clause linq with 2 parameter with operator OR don“t retrieve the values correctly
- Searching database with Linq
- Is it possible to use Linq to get a total count of items in a list of lists?
- CF Entity Framework filtering related data
- Get random and specific items from database
- LINQ Operations on Lambda Grouping
- Returning top 50% of list whilst evenly splitting rows between object property
- How can I return if an optional navigation property exists from an Entity Framework Query?
- How to assign value from properties to enum in Linq
- LINQ group by date - include empty days WITHOUT using join
- How to write a LINQ query resulting in a Dictionary?
- counter in lambda expression streamwriter
- Risks of using OData and IQueryable
- Joining a CSV file to query results
- How to Convert a String into Integer Array in C#
- A temporary table using LINQ
- Can you use a List to configure a selector in LINQ join query?
- Redirect method call within delegate
- Select parents with specific children in LINQ
- Using LINQ to remove duplicates in dictionary and the count of those duplicates
- Grafting LINQ onto C# 2 library
- How to analyse LINQ queries
- Why isn't this short circuit is not working in linq to sql query?
- Dbcontext disposed when iterating resulting list
- How to not print duplicates in a data grid view using LINQ
- programmatically add column key id linq
- Convert.ChangeType to produce an array of concrete type elements, not objects
- LINQ group by creating multiple keys for the same DateTime