title: Add new data into existing xml file
body: <p>I am writing a xml file from a employee class. now i want to add new record of employee into existing xml file . how can i do this?</p>
  
  <p>Now on a button click i want to add a new record of employee in XML.</p>
  
  <p>----- Xml file ----</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;metadata&gt;
    &lt;Employee ID="1" firstName="Usman" lastName="Shahzad" Salary="1000" /&gt;
    &lt;Employee ID="2" firstName="Mubasshir" lastName="Aashiq" Salary="1001" /&gt;
    &lt;Employee ID="3" firstName="Ishitiaq" lastName="Ch." Salary="1002" /&gt;
  &lt;/metadata&gt;
  </code></pre>
  
  <p>----- Code Behind -----</p>
  
  <pre><code>  private void btnGet_Click(object sender, EventArgs e)
          {
              Employee[] employees = new Employee[3];
              employees[0] = new Employee(1, "Usman", "Shahzad", 1000);
              employees[1] = new Employee(2, "Mubasshir", "Aashiq", 1001);
              employees[2] = new Employee(3, "Ishitiaq", "Ch.", 1002);
  
  
              XmlWriterSettings settings = new XmlWriterSettings();
              settings.Indent = true;
              string filename = @"Users\text1.xml";
              Directory.CreateDirectory(Path.GetDirectoryName(filename));
              using (XmlWriter xmlWriter = XmlWriter.Create(filename, settings))
              {
                  xmlWriter.WriteStartDocument();
                  xmlWriter.WriteStartElement("metadata");
                  foreach (Employee a in employees)
                  {
                      xmlWriter.WriteStartElement("Employee");
                      xmlWriter.WriteAttributeString("ID", Convert.ToString(a.Id));
                      xmlWriter.WriteAttributeString("firstName", Convert.ToString(a.FirstName));
                      xmlWriter.WriteAttributeString("lastName", Convert.ToString(a.LastName));
                      xmlWriter.WriteAttributeString("Salary", Convert.ToString(a.Salary));
                      xmlWriter.WriteEndElement();
                  }
                  xmlWriter.WriteEndElement();
              }
              DialogResult dr = MessageBox.Show("XML file creation Done\nDo you want to load it into grid view?", "Testing", MessageBoxButtons.OKCancel, MessageBoxIcon.Information);
              if (dr == DialogResult.OK)
              {
                  ds.ReadXml(@"Users\text1.xml");
                  dataGridView1.DataSource = ds.Tables[0];
              }
              else
                  return;
  
          }
          class Employee
          {
              Int32 _id;
              string _firstName;
              string _lastName;
              Int32 _salary;
  
              public Employee(Int32 id, string firstName, string lastName, Int32 salary)
              {
                  this._id = id;
                  this._firstName = firstName;
                  this._lastName = lastName;
                  this._salary = salary;
              }
  
              public Int32 Id { get { return _id; } }
              public string FirstName { get { return _firstName; } }
              public string LastName { get { return _lastName; } }
              public Int32 Salary { get { return _salary; } }
          }
  </code></pre>