Problem in saving data to an XML file RRS feed

  • Question

  • Hi, I'm coding a program in C# to save some data in to an XML file. I have 3 questions.
    1. I'm trying to save my account details in the XML file. The data I want to save is, Account name, Username, Password and Additional info(multiple lines). But I don't know how to arrange the data correctly in to XML elements. I need some help with that.
    2. I'm using below code to save data to the XML file. But when I try to save another record, it deletes the existing data from the XML file and then add the new record. So now I have only one record. How do I fix it?

    3. When saving additional info, I have to save multiple lines of information in a XML element how can I achieve that?

    the code I'm using right now is below,

    private void button1_Click(object sender, EventArgs e)
                if (Functions.SavetoXML(textBox1.Text, textBox2.Text, textBox3.Text, textBox4.Text) == true) 
                    XmlWriterSettings settings = new XmlWriterSettings();
                    settings.Indent = true;
                    XmlWriter writer = XmlWriter.Create("Passwords.rar", settings);
                    writer.WriteComment("This file is generated by PasswordSave.");
                    writer.WriteElementString("Name", "" + textBox1.Text);
                    writer.WriteElementString("Username", "" + textBox2.Text);
                    writer.WriteElementString("Password", "" + textBox3.Text);
                   // writer.WriteStartElement("Additinal Info", "" + textBox4.Text);
                    MessageBox.Show("Information Saved!", "Done", MessageBoxButtons.OK, MessageBoxIcon.Information);

    Wednesday, July 10, 2013 4:24 PM


All replies