title: Creating a dynamic xml document
body: <p>Hi you is it possible to create a dynamica xml with xdocument I've been trying but it appears that it returns an exception about having a wrong structure</p>
  
  <p>My code is the following</p>
  
  <pre><code>public string ReadTest(Stream csvFile)
          {
              XDocument responseXml = new XDocument( new XDeclaration("1.0", "utf-8", "yes"));   
  
              try
              {
                  if ( csvFile != null || csvFile.Length!=0)
                  {
                      responseXml.Add(new XElement("root"));
  
                      //using(CsvFileReader reader=new CsvFileReader(File.OpenRead(@"C:\Users\toshibapc\Documents\Visual Studio 2013\Projects\WCFLecturaCSV\WCFLecturaCSV\App_Data\archivo.csv"))){
                      using (CsvFileReader reader = new CsvFileReader(csvFile))
                      {
  
                          CsvRow row = new CsvRow();
                          List&lt;String&gt; headers = new List&lt;string&gt;();
  
  
                          while (reader.ReadRow(row))
                          {
                              int cont = 0;
  
                              XElement dato = new XElement("AccountInfos", new XElement("Info"));
                              XElement datos=null;
                              foreach (String s in row)
                              {
                                  if(s.Equals("AccountIDToMove", StringComparison.OrdinalIgnoreCase)|| s.Contains("AccountNameToMove") || s.Contains("NewParentAccountID") || s.Contains("NewParentAccountName")){
                                      headers.Add(s);                                    
                                  }
                                  else{
                                      if (s != String.Empty)
                                      {
                                          datos = new XElement(headers[cont], s); //.Append("&lt;" + headers[cont] + "&gt;" + s + "&lt;" + headers[cont] + "/&gt;");
                                          dato.Add(datos);
                                      }                                    
                                     }
                                  cont++;                                
                              }
                              if (headers.Count == 4 &amp;&amp; datos != null)
                                  responseXml.Add(dato);
  
                          } // fin de while 
                      }
  
                  } // Check if no file i sent or not info on file
  
              }
              catch (Exception ex) {
                  //oError = ex.Message;
              }
              return responseXml.ToString();
          }
  </code></pre>
  
  <p>What i would like to acomplish by using this code is to get an xml like this</p>
  
  <pre><code>&lt;xml version="1.0"&gt;
  &lt;root&gt;
  &lt;AccountInfos&gt;
  &lt;Info&gt;
  &lt;AccountIDToMove&gt;312456&lt;/AccountIDToMove&gt;
  &lt;AccountNameToMove&gt;Burger Count&lt;/AccountNameToMove&gt;
  &lt;NewParentAccountID&gt;453124&lt;/NewParentAccountID&gt;
  &lt;NewParentAccountName&gt; Testcom sales 1&lt;/NewParentAccountName&gt;
  &lt;/Info&gt;
  &lt;Info&gt;
  &lt;AccountIDToMove&gt;874145&lt;/AccountIDToMove&gt;
  &lt;AccountNameToMove&gt;Mac Count&lt;/AccountNameToMove&gt;
  &lt;NewParentAccountID&gt;984145&lt;/NewParentAccountID&gt;
  &lt;NewParentAccountName&gt; Testcom sales 1&lt;/NewParentAccountName&gt;
  &lt;/Info&gt;
  &lt;/AccountInfos&gt;
  &lt;/root&gt;
  </code></pre>
  
  <p>For any answer or help thank you so much</p>