<p>for example, I have the following xml document:</p>

<pre><code>def CAR_RECORDS = '''
    &lt;records&gt;
      &lt;car name='HSV Maloo' make='Holden' year='2006'/&gt;
      &lt;car name='P50' make='Peel' year='1962'/&gt;
      &lt;car name='Royale' make='Bugatti' year='1931'/&gt;
    &lt;/records&gt;
'''
</code></pre>

<p>and I want to move the car "Royale" up to first one, and insert a new car just after car"HSV Maloo", the result would be:</p>

<pre><code>'''
    &lt;records&gt;
      &lt;car name='Royale' make='Bugatti' year='1931'/&gt;
      &lt;car name='HSV Maloo' make='Holden' year='2006'/&gt;
      &lt;car name='My New Car' make='Peel' year='1962'/&gt;
      &lt;car name='P50' make='Peel' year='1962'/&gt;
    &lt;/records&gt;
'''
</code></pre>

<p>How to do it with Groovy? comments are welcome.</p>

<hand-wave>
these are not the codz you seek
</hand-wave>
```
```
Node root = new XmlParser().parseText(CAR_RECORDS)
NodeList carNodes = root.car
Node royale = carNodes[2]
carNodes.remove(royale)
carNodes.add(0, royale)
carNodes.add(2, new Node(root, 'car', [name:'My New Card', make:'Peel', year:'1962']))
```
```
I don't know if there's a smarter way to create new nodes... but that works for me.
EDIT: uhg... thanks guys... I got lazy and was printing carNodes when i tested this instead of the root... yikes.