// 定义树形节点类 public class TreeNode { public string Name { get; set; } public List<TreeNode> Children { get; set; } // 重载ToString方法,返回该节点及其子节点的XML标签和标签内容 public override string ToString() { StringWriter sw = new StringWriter(); XmlWriter writer = XmlWriter.Create(sw); writer.WriteStartElement(Name); if (Children != null) { foreach (TreeNode child in Children) { writer.WriteRaw(child.ToString()); } } writer.WriteEndElement(); return sw.ToString(); } }
标签:xml,转换,writer,sw,Children,json,ToString,节点,public From: https://www.cnblogs.com/LSYLY97/p/17246550.html