例如,我有以下 xml 文档:
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>
'''
我想将汽车“Royale”移动到第一个,并在汽车“HSV Maloo”之后插入一辆新车,结果将是:
'''
<records>
<car name='Royale' make='Bugatti' year='1931'/>
<car name='HSV Maloo' make='Holden' year='2006'/>
<car name='My New Car' make='Peel' year='1962'/>
<car name='P50' make='Peel' year='1962'/>
</records>
'''
如何用 Groovy 做到这一点?欢迎评论。