I went down a similar route to danb, but ran into problems when actually printing out the resulting XML. Then I realized that the NodeList that was returned by asking the root for all of it's "car" children isn't the same list as you get by just asking for the root's children. Even though they happen to be the same lists in this case, they wouldn't always be if there were non "car" children under the root. Because of this, reording the list of cars that come back from the query doesn't affect the initial list.
Here's a solution that appends and reorders:
def CAR_RECORDS = '''
<records>
<car name='HSV Maloo' make='Holden' year='2006'/>
<car name='P50' make='Peel' year='1962'/>
<car name='Royale' make='Bugatti' year='1931'/>
</records>
'''
def carRecords = new XmlParser().parseText(CAR_RECORDS)
def cars = carRecords.children()
def royale = cars.find { it.@name == 'Royale' }
cars.remove(royale)
cars.add(0, royale)
def newCar = new Node(carRecords, 'car', [name:'My New Car', make:'Peel', year:'1962'])
assert ["Royale", "HSV Maloo", "P50", "My New Car"] == carRecords.car*.@name
new XmlNodePrinter().print(carRecords)
The assertion with the propertly ordered cars passes, and the XmlNodePrinter outputs:
<records>
<car year="1931" make="Bugatti" name="Royale"/>
<car year="2006" make="Holden" name="HSV Maloo"/>
<car year="1962" make="Peel" name="P50"/>
<car name="My New Car" make="Peel" year="1962"/>
</records>