1

I'm trying to extract values from input xml and construct output xml using groovy. I'm getting below error .I took a small example to verify the logic.

 def xml1 = """
 <company type="bentley">
     <account>
      <dept1>IT</dept1>
      <dept2>Admin</dept2>
      <dept3>Security</dept3>
    </account>
</company>""" ;

def xml2 = """
<company type="NG">
    <account>
      <dept1></dept1>
      <dept2></dept2>
      <dept3></dept3>
     </account>
</company>""";

def rootnode1= new XmlParser().parseText(xml1);
def rootnode2= new XmlParser().parseText(xml2);

rootnode1.account.each {
rootnode2.account.dept1[0].value = it.dept1[0].text();
rootnode2.account.dept2[0].value = it.dept2[0].text();
}

Error: java.lang.IllegalArgumentException: argument type mismatch

Thanks, Venkat

Venkat
  • 11
  • 1

1 Answers1

0

It looks like you need to provide the each function a counter. Try something like the following:

rootnode1.account.each { n ->
rootnode2.account.dept1[0].value = n.dept1[0].text();
rootnode2.account.dept2[0].value = n.dept2[0].text();
}

Better still, if you have an unknown number of departments, you could move the .each() to the dept level.

Dan O'Boyle
  • 3,676
  • 5
  • 28
  • 44