title: how to convert xml to DataTable in C#
body: <p>My customer gave me a <code>webservice</code> which was written in ColdFusion and I have been trying to consume it with C#. I have been trying to convert XML to <code>DataTabl</code>e but I am getting a <code>DataTable</code> with no rows.</p>
  
  <p>Here is my XML:</p>
  
  <pre><code>&lt;?xml version='1.0' standalone='yes'?&gt;
  &lt;dtFirms&gt;
    &lt;NR&gt;2&lt;/NR&gt;
    &lt;NAME&gt;CS Net - 2014&lt;/NAME&gt;
    &lt;NRTIT&gt;2 - 2014 - CS Net - 2014&lt;/NRTIT&gt;
    &lt;PERIOD&gt;7&lt;/PERIOD&gt;
  &lt;/dtFirms&gt;
  </code></pre>
  
  <p>and this is my C# code. It always return empty DataTable. What am I doing wrong?</p>
  
  <pre><code>    public DataTable ReadXmlIntoDataTable(string s) {
  
      //create the DataTable that will hold the data
      DataTable table = new DataTable("dtFirms");
      try
      {
          //open the file using a Stream
          using (Stream stream = GenerateStreamFromString(s))
          {
              //create the table with the appropriate column names
              table.Columns.Add("NR", typeof(string));
              table.Columns.Add("NAME", typeof(string));
              table.Columns.Add("NRTIT", typeof(string));
              table.Columns.Add("PERIOD", typeof(int));
  
              //use ReadXml to read the XML stream
              table.ReadXml(stream);
  
              //return the results
              return table;
          }
      }
      catch (Exception ex)
      {
          return table;
      }
  }
  
  
  public Stream GenerateStreamFromString(string s)
  {
      MemoryStream stream = new MemoryStream();
      StreamWriter writer = new StreamWriter(stream);
      writer.Write(s);
      writer.Flush();
      stream.Position = 0;
      return stream;
  }
  </code></pre>
  
  <p>It always return empty DataTable. What am I doing wrong? Please help me.</p>