Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. i want to insert a new node regarding this code.but insert is not working..

i want to insert a new node regarding this code.but insert is not working..

Scheduled Pinned Locked Moved C#
htmlxmlquestion
5 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    samidhas
    wrote on last edited by
    #1

    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

    G 1 Reply Last reply
    0
    • S samidhas

      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

      G Offline
      G Offline
      Guffa
      wrote on last edited by
      #2

      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.

      S 1 Reply Last reply
      0
      • G Guffa

        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.

        S Offline
        S Offline
        samidhas
        wrote on last edited by
        #3

        no i am not getting the logic how to do it? an confustion in a code....

        G 1 Reply Last reply
        0
        • S samidhas

          no i am not getting the logic how to do it? an confustion in a code....

          G Offline
          G Offline
          Guffa
          wrote on last edited by
          #4

          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.

          S 1 Reply Last reply
          0
          • G Guffa

            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.

            S Offline
            S Offline
            samidhas
            wrote on last edited by
            #5

            i just want to insert a new node in the treeview and xml file both , where i can insert name and values from textbox.... will u help in for code?

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups