Need To Update XML Tag using Groovy -
i have below xml need update tags value 'cusip', 'fund'. using below code not helping me.
<?xml version="1.0" encoding="utf-8"?> <transactions asof_date="4/2/2014" create_date="4/2/2014" records="1"> <trade> <accrual_dt>4/1/2014</accrual_dt> <counterparty_code>1627</counterparty_code> <cusip>31384wps3</cusip> <desc_instmt>credit industriel et commercial (n</desc_instmt> <desk>a</desk> <desk_type>gen</desk_type> <dtm_2a7>7</dtm_2a7> <execution_time>4/1/2014 10:03:06.000</execution_time> <exec_time_source>a</exec_time_source> <fund>vimvp-fi</fund> <int_at_maturity>536.6666666667</int_at_maturity> <invnum>-911223</invnum> <trdcharge_set size="2"> - <trdcharge> <calc_type>flat</calc_type> <category>clrf</category> <trdcharge_amount>150.0000000000</trdcharge_amount> <rate>0.0000000000</rate> <trdcharge_schedule_id>-111111.0000000000</trdcharge_schedule_id> </trdcharge> - <trdcharge> <calc_type>flat</calc_type> <category>locl</category> <rate>0.0000000000</rate> <trdcharge_amount>50.0000000000</trdcharge_amount> <trdcharge_schedule_id>-111111.0000000000</trdcharge_schedule_id> </trdcharge> </trdcharge_set> </trade>
i using below code doing same-
def xmlfile = "d:\\invesco\\alladin\\test data files\\input\\transaction_fi.xml" def xml = new xmlparser(false, false).parse(xmlfile) xml.'**'.'trade'.each{ it.@fund = 'cash' it.@invnum = '-675' it.@cusip = '3b56gtunn' }
i need change tag value of trdcharge category locl
this works:
new xmlparser().parse(xmlfile).with { x -> x.trade.each { trade -> trade.children().find { -> it.name() == 'fund' }?.value = 'cash' trade.children().find { -> it.name() == 'invnum' }?.value = '-675' trade.children().find { -> it.name() == 'cusip' }?.value = '3b56gtunn' } println xmlutil.serialize(x) }
Comments
Post a Comment