How to update attribute of xml based on textbox value in C#

I will appreciate your help with this one.

I’ve written a code to enable me to modify the attribute of an xml element based on the value in the textbox.

Everything seems to work when debugged, but upto the last code, as the xml file deos not get updated. What am I doing wrong?

        private void btnUpdate_Click(object sender, EventArgs e)         {              XmlDocument doc = new XmlDocument();             doc.PreserveWhitespace = true;             doc.Load("Info.xml");              XmlNamespaceManager ns = new XmlNamespaceManager(doc.NameTable);             ns.AddNamespace("root", doc.DocumentElement.NamespaceURI);             XmlNode Body = doc.SelectSingleNode("//root:Body", ns);             ns.AddNamespace("child", Body.FirstChild.NextSibling.NamespaceURI);              XmlNode nodeIr = doc.SelectSingleNode("//child:Name", ns);              nodeIr.InnerText = txtBox1.Text;              doc.Save("Info.xml");          } 

I believe the last line needs to be modified.

Thank you

Add Comment
0 Answer(s)

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.