Need to update Tag value using Groovy -


i need update tag value of trdcharge_amount category test. have been able update values of other direct tag.

<?xml version="1.0" encoding="utf-8"?> <transactions asof_date="4/2/2014" create_date="4/2/2014" records="1">     <trade>         <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>test</category>            <rate>0.0000000000</rate>            <trdcharge_amount>1000.0000000000</trdcharge_amount>            <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>-112221.0000000000</trdcharge_schedule_id>        </trdcharge>     </trdcharge_set>     </trade> 

i have used below code don't know how update trdamount under trdcharge tag.

new xmlparser().parse(xmlfile).with { x ->     x.trade.each { aa ->         aa.children().find { -> it.name() == 'fund' }?.value = data[0]         aa.children().find { -> it.name() == 'invnum' }?.value = data[1]         aa.children().find { -> it.name() == 'cusip' }?.value = data[2]               aa.children().find { -> it.name() == 'tran_type' }?.value = data[3]         aa.children().find { -> it.name() == 'settle_exch_rate' }?.value = data[4]         aa.children().find { -> it.name() == 'trd_orig_face' }?.value = data[5]               aa.children().find { -> it.name() == 'trd_principal' }?.value = data[6]                }     def dir = "d:\\invesco\\alladin\\test data files\\input files through soapui\\"     def xfile1 = "transaction"+data[1]+".xml"     def xmlfile1 = dir+xfile1     def printer = new xmlnodeprinter(new printwriter(xmlfile1))     printer.preservewhitespace = true     printer.print(x) } 

you can this:

import groovy.xml.xmlutil  def example = ''' <transactions asof_date="4/2/2014" create_date="4/2/2014" records="1">   <trade>     <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>test</category>       <rate>0.0000000000</rate>       <trdcharge_amount>1000.0000000000</trdcharge_amount>       <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>-112221.0000000000</trdcharge_schedule_id>   </trdcharge>  </trdcharge_set>  </trade> </transactions> '''  new xmlparser().parsetext(example).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'     trade.trdcharge_set.trdcharge.each {         it.children().find { it.name() == 'trdcharge_amount'}?.value = 5.0     }   }   println xmlutil.serialize(x) } 

this changes trdcharge_amount values 5.0 , prints result.


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -