locked
How to save my XML file RRS feed

  • Question

  • User-1150629252 posted

    Hi,

    I have a TreeView to load my XML file with several nodes. Once i click the node i display it on a Textbox, now i need to Save after making changes to the whichever Selected Node i make changes to. Please help me.

    Friday, June 7, 2013 12:25 PM

Answers

  • User-1150629252 posted

    string filePath;
                filePath = txtFileName.Text;
                string[] paths = filePath.Split('\\');
                string xmlOnly = paths[paths.Length - 1]; //returns xml only from the text box..

                XmlDocument xmldoc = new XmlDocument();
                xmldoc.Load(xmlOnly);
                XmlNode newxmlnode = xmldoc.SelectSingleNode("Jobs/Job/JobTitle");

                foreach (XmlNode node in newxmlnode)
                {
                    node.Value = txtEditXML.Text;
                }
                //newxmlnode.InnerText = txtEditXML.Text;
                xmldoc.Save(xmlOnly);
                lblMessage.Text = "XML file modified successfully!";
                lblMessage.ForeColor = System.Drawing.Color.Green;
                lblMessage.Visible = true;
                treeViewMenu.Refresh();
            }

    this is my code...

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, June 7, 2013 3:13 PM

All replies

  • Friday, June 7, 2013 2:25 PM
  • User-1150629252 posted

    Hi, thanks this is good but i want it in WindowsForm...thanks

    Friday, June 7, 2013 2:46 PM
  • User-1150629252 posted

    string filePath;
                filePath = txtFileName.Text;
                string[] paths = filePath.Split('\\');
                string xmlOnly = paths[paths.Length - 1]; //returns xml only from the text box..

                XmlDocument xmldoc = new XmlDocument();
                xmldoc.Load(xmlOnly);
                XmlNode newxmlnode = xmldoc.SelectSingleNode("Jobs/Job/JobTitle");

                foreach (XmlNode node in newxmlnode)
                {
                    node.Value = txtEditXML.Text;
                }
                //newxmlnode.InnerText = txtEditXML.Text;
                xmldoc.Save(xmlOnly);
                lblMessage.Text = "XML file modified successfully!";
                lblMessage.ForeColor = System.Drawing.Color.Green;
                lblMessage.Visible = true;
                treeViewMenu.Refresh();
            }

    this is my code...

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, June 7, 2013 3:13 PM