c#treeview to xml错误

c#treeview to xml错误,c#,xml,treeview,C#,Xml,Treeview,我有下面的代码 using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Xml; namespace proj_TreeView_1 { public partial class FrmTreeView : Form { public FrmTre

我有下面的代码

using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Xml;

namespace proj_TreeView_1
{
public partial class FrmTreeView : Form
{
    public FrmTreeView()
    {
        InitializeComponent();
    }

    private void FrmTreeView_Load(object sender, EventArgs e)
    {

    }

    private void btnTransferToXml_Click(object sender, EventArgs e)
    {
            XmlDocument doc = new XmlDocument();
            XmlNode node = doc.CreateNode(XmlNodeType.Element,"root",null);
            foreach (TreeNode t in trViewContinent.Nodes)
            {
                node.AppendChild(getXmlNode(t, doc));
            }
            doc.AppendChild(node);
            doc.Save("C:\\Users\\stag0215\\Desktop\\Continets.xml");
    }
    private XmlNode getXmlNode(TreeNode tnode,XmlDocument doc)
    {
        XmlNode node = doc.CreateNode(XmlNodeType.Element, tnode.Text,null);

        foreach (TreeNode t in tnode.Nodes)
        {
            node.AppendChild(getXmlNode(t,doc));
        }

        return node;
    }
}
}
我得到了以下错误


XmlNode=doc.CreateNode(XmlNodeType.Element,tnode.Text,null) 十六进制值
0x20
指的是
空白
,作为
名称
的一部分输入该值无效。请更改您的名称(
删除空格
)以解决此问题。

感谢您的建议Sudhakar,它可以正常工作