title: Groovy script to split a file line at ',' and create a new XML file
body: <p>I am very new to Groovy and trying to figure my way out.</p>
  <p>I am trying to write a groovy to split the lines of a file on encountering ',' and then write a if condition based on the first two characters of the line. After that I wanted to create a XML file using the different data in the file. This is how far I have reached.</p>
  <pre><code>def Message processData(Message message) {
      //Body 
         def body = message.getBody(java.lang.String)as String;
         
         def varStringWriter = new StringWriter();
         def varXMLBuilder   = new MarkupBuilder(varStringWriter);
         
         String newItem ;
         body.eachLine{
              line -&gt; newItem = line ;
              String newItem1 = newItem.substring(0,2).trim();
              String newItem2 = newItem.substring(3,11).trim();
              varXMLBuilder.RECORD{
                  node1(newItem1);
                  node2(newItem2);
              }
          }
          def xml = varStringWriter.toString();
          xml=&quot;&lt;RECORDS&gt;&quot;+xml+&quot;&lt;/RECORDS&gt;&quot; ;
  
          message.setBody(xml);
          
         return message;
  }
  </code></pre>
  <p>In the above code I tried to use offset but, since each of my file lines are of different length it wont work.
  Please help me handle this issue.</p>
  <p>Regards,
  Nisha</p>