How to add new data in existing xml file?

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
Hi all ,
i want to save different user name and password in single XML file .
for this i wrote this code on save button :-

<span style="white-space:pre string filename = "E:\firstXML.xml";<br/>
XmlDocument xmlDoc = new XmlDocument();<br/>
XmlTextWriter xmlWriter = new XmlTextWriter(filename, System.Text.Encoding.UTF8);<br/>
xmlWriter.Formatting = Formatting.Indented;<br/>
xmlWriter.WriteProcessingInstruction("xml", "version=1.0 encoding=UTF-8");<br/>
xmlWriter.WriteStartElement("Credential");<br/>
xmlWriter.Close();<br/>
xmlDoc.Load(filename);<br/>
XmlNode root = xmlDoc.DocumentElement;<br/>
XmlElement childNode1 = xmlDoc.CreateElement("UserName");<br/>
XmlElement childNode2 = xmlDoc.CreateElement("Password");
<span style="white-space:pre root.AppendChild(childNode1);<br/>
childNode1.InnerText = tbName.Text;
<span style="white-space:pre root.AppendChild(childNode2);<br/>
childNode2.InnerText = tbPassword.Text;
<span style="white-space:pre xmlDoc.Save(filename);
USING THIS XML IS CREATING BUT NEXT TIME IF I AM INSERTING DIFFERENT USER NAME AND PASSWORD IT IS REPLACING MY PREVIOUS DATA. HOW TO ADD ALL USER NAME AND PASSWORD INTO SINGLE XML FILE PLEASE HELP.. <hr class="sig sumitk

View the full article
 
Back
Top