title: Groovy - Writing parts of response to file
body: <p>I want to write parts of response to file. File would look like:</p>
  
  <pre><code>Date_and_hour; city_name1; temperatureC
  Date_and_hour; city_name2; temperatureC
  </code></pre>
  
  <p>It for each test would make new line.
  I have problem with writing to file part of response, don't know how to do that.</p>
  
  <p>Response:</p>
  
  <pre><code>&lt;soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"&gt;
      &lt;soap:Body&gt;
          &lt;GetWeatherResponse xmlns="http://www.webserviceX.NET"&gt;
              &lt;GetWeatherResult&gt;&lt;![CDATA[&lt;?xml version="1.0" encoding="utf-16"?&gt;
                  &lt;CurrentWeather&gt;
                      &lt;Location&gt;NEWPORT STATE AIRPORT, RI, United States (KUUU) 41-32N 071-17W 51M&lt;/Location&gt;
                      &lt;Time&gt;Aug 20, 2014 - 04:10 AM EDT / 2014.08.20 0810 UTC&lt;/Time&gt;
                      &lt;Wind&gt; Calm:0&lt;/Wind&gt;
                      &lt;Visibility&gt; 3/4 mile(s):0&lt;/Visibility&gt;
                      &lt;SkyConditions&gt; obscured&lt;/SkyConditions&gt;
                      &lt;Temperature&gt; 57.9 F (14.4 C)&lt;/Temperature&gt;
                      &lt;DewPoint&gt; 55.9 F (13.3 C)&lt;/DewPoint&gt;
                      &lt;RelativeHumidity&gt; 93%&lt;/RelativeHumidity&gt;
                      &lt;Pressure&gt; 29.97 in. Hg (1014 hPa)&lt;/Pressure&gt;
                      &lt;Status&gt;Success&lt;/Status&gt;
                  &lt;/CurrentWeather&gt;]]&gt;&lt;/GetWeatherResult&gt;
          &lt;/GetWeatherResponse&gt;
      &lt;/soap:Body&gt;
  &lt;/soap:Envelope&gt;
  </code></pre>
  
  <p>Groovy code:</p>
  
  <pre><code>import com.eviware.soapui.support.XmlHolder
  import java.text.MessageFormat
  import org.apache.commons.lang.ObjectUtils
  
  def groovyUtils = new com.eviware.soapui.support.GroovyUtils( context )
  def retrieve = groovyUtils.getXmlHolder("GetWeather#Response")
  if (!ObjectUtils.equals(retrieve.getNodeValue("//*:Location"), "string")){
      def currentTime = System.currentTimeMillis()
      def fullFilePath = context.expand("d:/Groovy/Scripts") + File.separator + "File.txt"
      def reportFile = new File(fullFilePath)
      if (!reportFile.exists())
      {
          reportFile.createNewFile()
          reportFile.append((Object)retrieve.getPrettyXml(), 'UTF-16')
      }
  }
  </code></pre>