title: Groovy: Node.replaceNode with Node?
body: <p>Suppose I have a node I'd like to replace with <code>replaceNode</code>, however, I don't want to use a <code>Builder</code> to do it - or rather, I already have the node with which to replace it:</p>
  
  <pre><code>replacement = new XmlParser.parse('input.xml')
  root.depthFirst().replaceme.each { it -&gt;
    it.replaceNode { node -&gt;
      // This is what I can't figure out
    }
  }
  </code></pre>
  
  <p>I've tried lots of different iterations, but can't seem to work it out.  If I just return text in that segment, it replaces the node with an empty node.</p>
  
  <p>For example, if my input file is this:
      
        This should get replaced
      </p>
  
  <p>And I have a replacement like this:
      This will replace the <i>Original</i></p>
  
  <p>I'd like to do something like:</p>
  
  <pre><code>top = new XmlParser().parseFile('input.xml')
  top.middle.each { it -&gt;
    it.replaceNode { node -&gt;
      new XmlParser().parseFile('replacement.xml')
    }
  }
  </code></pre>