title: Display the datatable in xml c#
body: <p>I'm trying to create a xml file with the data in my dataTable. Ultimately, this is what I want to create</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;regisApts xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"&gt;
    &lt;JobList&gt;
      &lt;Job id="1245"&gt;
        &lt;Date&gt;2010-07-25&lt;/Date&gt;
        &lt;Reason&gt;No Access 1&lt;/Reason&gt;
        &lt;Comment&gt;Tenant is on holiday&lt;/Comment&gt;
        &lt;ExternalJobNumber&gt;123456&lt;/ExternalJobNumber&gt;
      &lt;/Job&gt;
      &lt;Job id=""&gt;
        &lt;Date&gt;2010-07-26&lt;/Date&gt;
        &lt;Reason&gt;No Access 2&lt;/Reason&gt;
        &lt;Comment&gt;Tenant out at work&lt;/Comment&gt;
        &lt;ExternalJobNumber&gt;123456&lt;/ExternalJobNumber&gt;
      &lt;/Job&gt;
      &lt;Job id="1453"&gt;
        &lt;Date&gt;2010-07-25&lt;/Date&gt;
        &lt;Reason&gt;No Access 1&lt;/Reason&gt;
        &lt;Comment&gt;Tenant in hospital&lt;/Comment&gt;
      &lt;/Job&gt;
    &lt;/JobList&gt;
  &lt;/regisApts&gt;
  </code></pre>
  
  <p>I managed to generate a xml with foreach, but it's overiding the xml when inserting the next row. Any help is really appreciated. Thanks</p>
  
  <pre><code>foreach (DataRow row in dt.Rows)
  {
      xmlCostCode = row["CostCode"].ToString();
      xmlReason = row["Reason"].ToString();
      xmlComment = row["PropertyCode"].ToString();
      xmlFilePath = xmlFolderPath + "test" + ".xml";
  
      xmlContent = "&lt;JobList&gt;&lt;Job Id=\"" + xmlCostCode + "\"&gt;&lt;Date&gt;2017-07-18&lt;/Date&gt;&lt;Reason&gt;" + xmlReason + "&lt;/Reason&gt;&lt;Comment&gt;" + xmlComment + "&lt;/Comment&gt;&lt;/Job&gt;&lt;/JobList&gt;";
  
      XmlDocument xdoc = new XmlDocument();
      xdoc.LoadXml(xmlContent);
      xdoc.Save(xmlFilePath);
  }
  </code></pre>
  
  <p>Results I get</p>
  
  <pre><code>&lt;JobList&gt;
      &lt;Job id="1245"&gt;
        &lt;Date&gt;2010-07-25&lt;/Date&gt;
        &lt;Reason&gt;No Access 1&lt;/Reason&gt;
        &lt;Comment&gt;Tenant is on holiday&lt;/Comment&gt;
        &lt;ExternalJobNumber&gt;123456&lt;/ExternalJobNumber&gt;
      &lt;/Job&gt;
  &lt;JobList&gt;
  </code></pre>