我已经写了:
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();
}
在 xml 文件上运行此递归方法的结果显示:
Videos
------Video
------------Title
------------Director
------------Actors
------------------Actor
------------------Actor
------------------Actor
------------------Actor
------------Length
------------Format
------------Rating
------Video
------------Title
------------Director
------------Length
------------Format
------------Rating
enter code here
但我希望输出如下所示:
Videos
------Video
------------Title
------------Director
------------Actors
------------------Actor
------------Length
------------Format
------------Rating
如何编辑代码?从昨天开始真的很挣扎......