我有这样的xml结构:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<service>
<Income>
<localTaxes>
<details>
<start>2017-09-07</start>
<startDate>2017-02-02</startDate>
<endDate>2017-03-02</endDate>
<runAs>false</runAs>
<makeVersion>1</makeVersion>
<patch>this is patch</patch>
<parameter>1</parameter>
</details>
</localTaxes>
<TaxyFree>
<details>
<start>2017-09-07</start>
<startDate>2017-02-02</startDate>
<endDate>2017-03-02</endDate>
<runAs>false</runAs>
<makeVersion>1</makeVersion>
<patch>this is patch</patch>
<parameter>1</parameter>
</details>
</TaxyFree>
</rs>
</Income>
在我的groovy代码中,我想只更新localTaxes并保持其他数据不变,现在我有如下代码,但结果我只能更新localTaxes,除此之外没有任何数据(我的意思是我只有&lt; service><Income><locaTaxes>...</localTaxes></Income></service>
localTaxes标记及其相关数据,我应该如何更改我的代码才能更新locaTaxes并使xml的其他部分成为不可变的?: < / p>
def root = new XmlSlurper().parseText(content);
def listOfMaps = root.rs.borderCross.details.collect { node -> [
start: node.start.text(),
startDate: node.startDate.text(),
endDate: node.endDate.text(),
patch:node.patch.text(),
runAs:node.runAs.text(),
makeVersion:node.makeVersion.text(),
parameter:node.parameter.text()
]
} def process = { binding, element, name ->
if( element[ name ] instanceof Collection ) {
element[ name ].each { n ->
binding."$name"( n )
}
}
else if( element[ name ] ) {
binding."$name"( element[ name ] )
}
}
material= XmlUtil.serialize( new StreamingMarkupBuilder().with { builder ->
builder.bind { binding ->
service{
rs {
listOfMaps.each { e ->
borderCross {
process(binding, e, 'start')
process(binding, e, 'startDate')
process(binding, e, 'endDate')
process(binding, e, 'runAs')
process(binding, e, 'makeVersion')
process(binding, e, 'parameter')
}
}
}
}
}
} )