title: c# how to convert csv to xml
body: <p>i know the basic for converting a CSV file to an XML but my CSV files has different columns and i also need it to split it differently.How am i able to use C# and convert my CSV file to this XML file? thanks for your help!</p>
  
  <pre><code>        &lt;CARS&gt;
         &lt;NAME="amk"&gt;
           &lt;CAR&gt;
              &lt;id&gt;A1&lt;/id&gt;
              &lt;start&gt;12.00&lt;/start&gt;
              &lt;end&gt;11.59&lt;/end&gt;
              &lt;place&gt;PARK&lt;/place&gt;
              &lt;day&gt;DAY&lt;/day&gt;
              &lt;letter&gt;abc&lt;/letter&gt;
              &lt;number&gt;77&lt;/number&gt;
           &lt;/CAR&gt;
  
           &lt;CAR&gt;
              &lt;id&gt;A2&lt;/id&gt;
              &lt;start&gt;01.00&lt;/start&gt;
              &lt;end&gt;12.59&lt;/end&gt;
              &lt;place&gt;garden&lt;/place&gt;
              &lt;day&gt;night&lt;/day&gt;
              &lt;letter&gt;abc&lt;/letter&gt;
              &lt;number&gt;27&lt;/number&gt;
              &lt;length&gt;2.15M&lt;/length&gt;
              &lt;amount&gt;12&lt;/amount&gt;
           &lt;/CAR&gt;
  
           &lt;CAR&gt;...&lt;/CAR&gt;
  
           &lt;CAR&gt;...&lt;/CAR&gt;
  
          &lt;NAME="bbk"&gt;
           &lt;CAR&gt;
              &lt;id&gt;B1&lt;/id&gt;
              &lt;start&gt;23.59&lt;/start&gt;
              &lt;end&gt;11.59&lt;/end&gt;
              &lt;place&gt;Rooftop&lt;/place&gt;
              &lt;day&gt;DAY&lt;/day&gt;
              &lt;letter&gt;abc&lt;/letter&gt;
              &lt;number&gt;34&lt;/number&gt;
           &lt;/CAR&gt;
  
           &lt;CAR&gt;
              &lt;id&gt;B4&lt;/id&gt;
              &lt;start&gt;01.00&lt;/start&gt;
              &lt;end&gt;02.00&lt;/end&gt;
              &lt;place&gt;garden&lt;/place&gt;
              &lt;day&gt;Day&lt;/day&gt;
              &lt;letter&gt;abc&lt;/letter&gt;
              &lt;number&gt;27&lt;/number&gt;
              &lt;length&gt;2.00M&lt;/length&gt;
              &lt;amount&gt;2&lt;/amount&gt;
           &lt;/CAR&gt;
  
               &lt;CAR&gt;...&lt;/CAR&gt;
  
               &lt;CAR&gt;...&lt;/CAR&gt;
  
  
           &lt;/NAME&gt;
      &lt;/CARS&gt;
  
  
  
  public static void ConvertCsvToXML()
          {
              String[] FileContent = File.ReadAllLines(@"C:\test.csv");
              String XMLNS = "";
              XElement Inv = new XElement("CARS",
  
              from AREA in FileContent
              let fields = AREA.Split(',')
              select new XElement("Area", fields[0]),
  
              from CAR in FileContent
              let fields = CAR.Split(',')
              select new XElement("Car",
              new XElement("id", fields[1]),
              new XElement("start", fields[2]),
              new XElement("end", fields[3]),
              new XElement("place", fields[4]),
              new XElement("day", fields[5]),
              new XElement("letter", fields[6]),
              new XElement("number", fields[7]),
              new XElement("length", fields[8]),
              new XElement("amount", fields[9])
              )
              );
              File.WriteAllText(@"C:\testCSV.xml", XMLNS + Inv.ToString());
          }
  </code></pre>
  
  <p>There is more than a hundred data BUT with different amount of columns and rows needed to be import to the XML from CSV.please help!
  this is the codes i've been using so far,but it wont works for me as i dun have a certain row, some data i need 7 rows some i need 9 or 10.plus i need to create a new category like &lt; NAME ="bbk" > and put in data in it. thanks for your help.</p>
  
  <p>My CSV sourse code eg is  amk, A1,12.00,11.59,PARK,DAY,abc,77 A1,01.00,12.59,garden,night,abc,27,2.15M,12 bbk, B1,23.59,11.59,Rooftop,DAY,abc,34 B4,01.00,02.00,garden,Day,abc,27,2.00M,2 
  Please tell me how i need to change my CSV code to let my desired XML output to be working. thanks!</p>