title: Generate XML with attribute and value in Spark(scala) using databricks
body: <p>I wanted to create a nested XML from CSV/DataFrame in scala spark. I am using Databricks spark-XML library for converting the DataFrame to XML format.</p>
  
  <p>I was trying to create an output like below, but unable to achieve it</p>
  
  <pre><code>&lt;rows&gt; 
  &lt;row&gt;
  &lt;name id=10&gt;Mahashree&lt;/name&gt;
  &lt;/row&gt;
  &lt;/rows&gt;
  </code></pre>
  
  <p>I have tried with struct</p>
  
  <pre><code>{"_VALUE":"Mahashree","_id":10}
  </code></pre>
  
  <p>but resulted as below </p>
  
  <pre><code>&lt;rows&gt; 
  &lt;row&gt;
  &lt;name id=10 VALUE="Mahashree"&gt;&lt;/name&gt;
  &lt;/row&gt;
  &lt;/rows&gt;
  </code></pre>
  
  <p>In DataBricks Documentation they have documentation for converting the nested XML but not to nested XML.</p>
  
  <pre><code>&lt;one&gt;
      &lt;two myTwoAttrib="BBBBB"&gt;two&lt;/two&gt;
      &lt;three&gt;three&lt;/three&gt;
  &lt;/one&gt;
  </code></pre>
  
  <p>produces a schema below:</p>
  
  <pre><code>root
   |-- two: struct (nullable = true)
   |    |-- _VALUE: string (nullable = true)
   |    |-- _myTwoAttrib: string (nullable = true)
   |-- three: string (nullable = true)
  </code></pre>
  
  <p>can anyone help to the nested element with attributes?</p>
  
  <p>Thanks in Advance</p>