0

I've the below code

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;
    }
}
}

and i'm getting the following error

XmlNode node = doc.CreateNode(XmlNodeType.Element, tnode.Text,null); <---- The ' ' character, hexadecimal value 0x20, cannot be included in a name.

thanks for your help

Paul Lo
  • 6,032
  • 6
  • 31
  • 36
Saif
  • 5
  • 2

1 Answers1

0

hexadecimal value 0x20 referes to Whitespace and it is not a valid value to enter as part of name.please change your name (remove space) to resolve the issue.

Sudhakar Tillapudi
  • 25,935
  • 5
  • 37
  • 67