I have written:
public string GetOutline(int indentLevel, XElement element)
{
StringBuilder result = new StringBuilder();
result = result.AppendLine(new string('-', indentLevel * 2) + element.Name);
foreach (var childElement in element.Elements())
{
result.Append(GetOutline(indentLevel + 3, childElement));
}
return result.ToString();
}
The result of this recursive methond run on xml file shows:
Videos
------Video
------------Title
------------Director
------------Actors
------------------Actor
------------------Actor
------------------Actor
------------------Actor
------------Length
------------Format
------------Rating
------Video
------------Title
------------Director
------------Length
------------Format
------------Rating
enter code here
But I would want the output to be like below:
Videos
------Video
------------Title
------------Director
------------Actors
------------------Actor
------------Length
------------Format
------------Rating
How to edit the code ? Really struggling with this from yesterday …
Use linq grouping by name:
instead of:
The only problem of this method is the use of
First.If you have, for example in your XML file:
With grouping and
Firstthe result will be:How do you want the result to appear in this case?
or
or this case will not appear?
UPDATE:
Given your comment the solution would be: