forum

Home / DeveloperSection / Forums / Adding multiple Records to the XML file

Adding multiple Records to the XML file

Anonymous User174704-Sep-2013

I would like to add multiple records to the xml file and here is the code which I’m using,

XmlTextWriter xwriter = new XmlTextWriter("C:\\Users\\Desktop\\TestFolder\\Xdoc1.xml", Encoding.UTF8);

xwriter.Formatting = Formatting.Indented;

xwriter.WriteStartElement("Employee");

xwriter.WriteStartElement("Person");

xwriter.WriteStartElement("Name");

xwriter.WriteString(textBox1.Text);

xwriter.WriteEndElement();

xwriter.WriteStartElement("Designation");

xwriter.WriteString(textBox2.Text);

xwriter.WriteEndElement();

xwriter.WriteStartElement("Employee ID");

xwriter.WriteString(textBox3.Text);

xwriter.WriteEndElement();

xwriter.WriteStartElement("Email");

xwriter.WriteString(textBox4.Text);

xwriter.WriteEndElement();

xwriter.WriteEndElement();

xwriter.WriteEndElement();

xwriter.Close();

The problem with this code is that only one record can be added. When i try to add the 2nd record, the previous record is overwritten.


Updated on 04-Sep-2013
I am a content writter !

Can you answer this question?


Answer

1 Answers

Liked By