title: Convert CSV file to XML
body: <p>I need to Convert a CSV into an XML document. The examples I have seen so far, all show how to do this with a fixed number of columns in the CSV.</p>
  
  <p>I have this so far, using LINQ:</p>
  
  <pre><code>String[] File = File.ReadAllLines(@"C:\text.csv");
  
          String xml = "";
  
          XElement top = new XElement("TopElement",
  
          from items in File
  
          let fields = items.Split(';')
  
          select new XElement("Item",
  
          new XElement("Column1", fields[0]),
  
          new XElement("Column2", fields[1]),
  
          new XElement("Column3", fields[2]),
  
          new XElement("Column4", fields[3]),
  
          new XElement("Column5", fields[4])
  
          )
  
          );
  
          File.WriteAllText(@"C:\xmlout.xml", xml + top.ToString());
  </code></pre>
  
  <p>This is for a fixed amount of columns, but my .CSV has a different number of columns on each line.</p>
  
  <p>How would you fit some sort of loop into this, depending on how many words (columns) there are in each line of the .CSV?</p>
  
  <p>Thnx</p>