Accepted answer

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)

This example produces the following output:



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.

  1. we need the structure of the xml as it would appear in your scenario. nesting and all.
  2. 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.

Related Query

More Query from same tag