title: Most Efficient way to create XML from java List object
body: <p>i am working on converting CSV to XML, though i have many ways to do this but my requirement is to do it in such a way that in future the mapping can be changed without any code change.
  so we are using the following approach.
  we are using Apache camel for the integration so CSV is being converted out of the box by camel and is being provided as a <code>List&lt;List&lt;String&gt;&gt;</code>
  with data something like</p>
  
  <pre><code>{[header1,header2,header3],[1,2,3],[2,4,5]}
  </code></pre>
  
  <p>i need to convert this list data to XML is the defined form but since i can't use the java mapping so was planning to do something like
  to convert this List in to a flat XML file using <code>XStream</code> and than use xslt to map the raw XML file to xslt, but when i am XStream to convert List to XML it giving following output</p>
  
  <pre><code>&lt;list&gt;
    &lt;java.util.Arrays_-ArrayList&gt;
      &lt;a class="string-array"&gt;
        &lt;string&gt;Quantity&lt;/string&gt;
        &lt;string&gt;Price&lt;/string&gt;
        &lt;string&gt;Total&lt;/string&gt;
        &lt;string&gt;Date&lt;/string&gt;
        &lt;string&gt;ID&lt;/string&gt;
        &lt;string&gt;Name&lt;/string&gt;
        &lt;string&gt;Ref#&lt;/string&gt;
      &lt;/a&gt;
    &lt;/java.util.Arrays_-ArrayList&gt;
    &lt;java.util.Arrays_-ArrayList&gt;
      &lt;a class="string-array"&gt;
        &lt;string&gt;4&lt;/string&gt;
        &lt;string&gt;1.13&lt;/string&gt;
        &lt;string&gt;4.52&lt;/string&gt;
        &lt;string&gt;9/4/2008&lt;/string&gt;
        &lt;string&gt;275&lt;/string&gt;
        &lt;string&gt;Blue Ink&lt;/string&gt;
        &lt;string&gt;49385730&lt;/string&gt;
      &lt;/a&gt;
    &lt;/java.util.Arrays_-ArrayList&gt;
    &lt;java.util.Arrays_-ArrayList&gt;
      &lt;a class="string-array"&gt;
        &lt;string&gt;5&lt;/string&gt;
        &lt;string&gt;2.16&lt;/string&gt;
        &lt;string&gt;2.16&lt;/string&gt;
        &lt;string&gt;8/3/2008&lt;/string&gt;
        &lt;string&gt;229&lt;/string&gt;
        &lt;string&gt;Red Ink&lt;/string&gt;
        &lt;string&gt;20549348&lt;/string&gt;
      &lt;/a&gt;
  </code></pre>
  
  <p>my sample CSV is </p>
  
  <pre><code>Quantity,Price,Total,Date,ID,Name,Ref#
  4,1.13,4.52,9/4/2008,275,Blue Ink,49385730
  5,2.16,2.16,8/3/2008,229,Red Ink,20549348
  </code></pre>
  
  <p>so it seems not possible to map this raw XML to the required XML using XSLT.
  Is there any way to convert this List data in to some more presentable XML format so that we can map that XML with XSLT to avoid any code change.
  Or is there any other more efficient way to convert this list in to XML structure</p>
  
  <p>Thanks in advance</p>