title: Processing XML string inside Spark UDF and return Struct Field
body: <p>I have a dataframe column named Body(String). The body column data looks like this</p>
  
  <pre><code>&lt;p&gt;I want to use a track-bar to change a form's opacity.&lt;/p&gt;
  
  &lt;p&gt;This is my code:&lt;/p&gt;
  
   &lt;pre&gt;&lt;code&gt;decimal trans = trackBar1.Value / 5000;
  this.Opacity = trans;
  &lt;/code&gt;&lt;/pre&gt;
  
  &lt;p&gt;When I build the application, it gives the following error:&lt;/p&gt;
  
  &lt;blockquote&gt;
    &lt;p&gt;Cannot implicitly convert type 'decimal' to 'double'.&lt;/p&gt;
  &lt;/blockquote&gt;
  
  &lt;p&gt;I tried using &lt;code&gt;trans&lt;/code&gt; and &lt;code&gt;double&lt;/code&gt; but then the 
  control doesn't work. This code worked fine in a past VB.NET project. &lt;/p&gt;
  ,While applying opacity to a form should we use a decimal or double value?
  </code></pre>
  
  <p>Using Body I want to prepare two separate columns code and text. Code is between elements named code and text is everything else.</p>
  
  <p>I have created a UDF which looks like this</p>
  
  <pre><code> case class bodyresults(text:String,code:String)
   val Body:String=&gt;bodyresults=(body:String)=&gt;{ val xmlbody=scala.xml.XML.loadString(body)
  val code = (xmlbody \\ "code").toString;
  val text = "I want every thing else as text. what should I do"
  (text,code)
  }
  val bodyudf=udf(Body)
  val posts5=posts4.withColumn("codetext",bodyudf(col("Body")))
  </code></pre>
  
  <p>This is not working. My questions are
  1.As you can see there is no root node in the data. can I still use scala XML parsing?
  2. how to parse everything else except code into text.</p>
  
  <p>If there is something wrong in my code please let me know </p>
  
  <p>Expected output:</p>
  
  <pre><code> (code,text)
   code = decimal trans = trackBar1.Value / 5000;this.Opacity = trans;trans double  
   text = everything else  
  </code></pre>