title: Groovy - Adding node to existing XML file with echoxml
body: <p>I am trying to insert a node into an existing XML document.
  I use groovy and ANT for that.</p>
  
  <p>So does my XML look like:</p>
  
  <pre><code>&lt;root&gt;
   &lt;node1 db="a" 
     user="test"/&gt;
  &lt;/root&gt;
  </code></pre>
  
  <p>Within this XML file I have a groovy section that looks that way:</p>
  
  <p>My groovy script, embedded in the ANT xml file.</p>
  
  <pre><code>&lt;target name="some-target"&gt;
   &lt;script language="groovy"&gt;
   def fragment = '''&amp;lt;root&amp;gt;
   &amp;lt;node1 db=&amp;quot;a&amp;quot; 
     user=&amp;quot;test&amp;quot;/&amp;gt;
  &amp;lt;/root&amp;gt;''';
  
  def parser = new XmlParser();
  xml.appendNode{fragment};
  
  def xmlOutput = new StringWriter();
  def xmlNodePrinter = new XmlNodePrinter(new PrintWriter(xmlOutput));      
  xmlNodePrinter.print(xml);
  </code></pre>
  
  <p>Now, I just want to add a second node, but I do not how to achieve that?</p>
  
  <p>If I add now a second node I always get the following output in the result:</p>
  
  <pre><code>&lt;root&gt;
   &lt;node1 db="a" 
     user="test"/&gt;
     &lt;Script1$_run_closure2@451001e5/&gt;
  &lt;/root&gt;
  </code></pre>
  
  <p>Thank you for your help in advance!</p>