i want to insert a new node regarding this code.but insert is not working..
-
private System.Windows.Forms.GroupBox grpbox; XPathDocument dom; XmlDocument doc; XPathNavigator nav; XPathExpression expr; XPathNodeIterator iterator; int cnt=0; Label lbl; TextBox txt; OpenFileDialog dlg; TreeNode newTreeNode; //int cnt = e.Node.GetNodeCount(false); //string filename; private void Form1_Load(object sender, System.EventArgs e) { //label1.Text = "File Path"; //label1.SetBounds(8, 8, 50, 20); //filename = Application.StartupPath + "\\Sample.xml"; //textBox1.Text= filename; //textBox1.SetBounds(64, 8, 256, 20); button1.Text = "Populate the TreeView with XML"; button1.SetBounds(8, 20, 200, 20); treeXml.Height = 600; treeXml.Width = 400; grpbox = new GroupBox(); grpbox.Height = 600; grpbox.Width = 400; grpbox.SetBounds(500, 2, 700, 600); grpbox.Visible = true; grpbox.Dock.Equals(Right); grpbox.Show(); this.Controls.Add(grpbox); //dom = new XPathDocument(dlg.FileName); } private void ConvertXmlNodeToTreeNode(XmlNode xmlNode, TreeNodeCollection treeNodes) { TreeNode newTreeNode = treeNodes.Add(xmlNode.Name); switch (xmlNode.NodeType) { case XmlNodeType.ProcessingInstruction: case XmlNodeType.XmlDeclaration: newTreeNode.Text = "<?" + xmlNode.Name + " " + xmlNode.Value + "?>"; break; case XmlNodeType.Element: if (xmlNode.Name.ToLower().Equals("node") == true) { newTreeNode.Text = "<" + xmlNode.Attributes["label"].Value.ToString() + ">"; } else newTreeNode.Text = "<" + xmlNode.Name + ">"; break; case XmlNodeType.Attribute: newTreeNode.Text = xmlNode.Name; // newTreeNode.Text = "ATTRIBUTE: " + xmlNode.Name; break; case XmlNodeType.Text: case XmlNodeType.CDATA: newTreeNode.Text = xmlNode.Value; break; case XmlNodeType.Comment: newTreeNode.Text = "<!--" + xmlNode.Value + "-->"; break; } if (xmlNode.Attributes != null) { foreach (XmlAttribute attribute in xmlNode.Attributes) { ConvertXmlNodeToTreeNode(attribute, newTreeNode.Nodes); } } foreach (XmlNode childNode in xmlNode.ChildNodes) { ConvertXmlNodeToTreeNode(childNode, newTreeNode.Nodes); } } private void treeXml_AfterSelect(object sender, System.Windows.Forms.TreeViewEventArgs e) { cnt = e.No
-
private System.Windows.Forms.GroupBox grpbox; XPathDocument dom; XmlDocument doc; XPathNavigator nav; XPathExpression expr; XPathNodeIterator iterator; int cnt=0; Label lbl; TextBox txt; OpenFileDialog dlg; TreeNode newTreeNode; //int cnt = e.Node.GetNodeCount(false); //string filename; private void Form1_Load(object sender, System.EventArgs e) { //label1.Text = "File Path"; //label1.SetBounds(8, 8, 50, 20); //filename = Application.StartupPath + "\\Sample.xml"; //textBox1.Text= filename; //textBox1.SetBounds(64, 8, 256, 20); button1.Text = "Populate the TreeView with XML"; button1.SetBounds(8, 20, 200, 20); treeXml.Height = 600; treeXml.Width = 400; grpbox = new GroupBox(); grpbox.Height = 600; grpbox.Width = 400; grpbox.SetBounds(500, 2, 700, 600); grpbox.Visible = true; grpbox.Dock.Equals(Right); grpbox.Show(); this.Controls.Add(grpbox); //dom = new XPathDocument(dlg.FileName); } private void ConvertXmlNodeToTreeNode(XmlNode xmlNode, TreeNodeCollection treeNodes) { TreeNode newTreeNode = treeNodes.Add(xmlNode.Name); switch (xmlNode.NodeType) { case XmlNodeType.ProcessingInstruction: case XmlNodeType.XmlDeclaration: newTreeNode.Text = "<?" + xmlNode.Name + " " + xmlNode.Value + "?>"; break; case XmlNodeType.Element: if (xmlNode.Name.ToLower().Equals("node") == true) { newTreeNode.Text = "<" + xmlNode.Attributes["label"].Value.ToString() + ">"; } else newTreeNode.Text = "<" + xmlNode.Name + ">"; break; case XmlNodeType.Attribute: newTreeNode.Text = xmlNode.Name; // newTreeNode.Text = "ATTRIBUTE: " + xmlNode.Name; break; case XmlNodeType.Text: case XmlNodeType.CDATA: newTreeNode.Text = xmlNode.Value; break; case XmlNodeType.Comment: newTreeNode.Text = "<!--" + xmlNode.Value + "-->"; break; } if (xmlNode.Attributes != null) { foreach (XmlAttribute attribute in xmlNode.Attributes) { ConvertXmlNodeToTreeNode(attribute, newTreeNode.Nodes); } } foreach (XmlNode childNode in xmlNode.ChildNodes) { ConvertXmlNodeToTreeNode(childNode, newTreeNode.Nodes); } } private void treeXml_AfterSelect(object sender, System.Windows.Forms.TreeViewEventArgs e) { cnt = e.No
-
What do you mean by "not working"? What happens? (And "nothing" never happens...) Do you get any error message?
Experience is the sum of all the mistakes you have done.
-
Well, if you don't explain what it is that you are trying to do with the code, it's even more confusing for someone who hasn't written it...
Experience is the sum of all the mistakes you have done.