Users Pricing

forum

Home Forums Adding multiple Records to the XML file – MindStick

Adding multiple Records to the XML file

Anonymous User 2160 04 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.


1 Answers

Markdown for AI

A clean, structured version of this page for AI assistants and LLMs.

Open .md