首页 > 其他分享 >json文件转换xml

json文件转换xml

时间:2023-03-23 10:34:15浏览次数:37  
标签:xml 转换 writer sw Children json ToString 节点 public

// 定义树形节点类
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

相关文章