AnsweredAssumed Answered

How to split XML Element Nodes using Groovy By its Count

Question asked by siva9055 on Jul 31, 2018
Latest reply on Jul 31, 2018 by trey.yeager826393

Hi all,

            I'm trying to split XML Document Nodes using Groovy Scripting in the Data Process Shape by its count value. But I am not getting to split the nodes using this logic.

 

            Below you can see the XML data in that wanted to split it by person node count should be equal to People data maincount. And I've also posted my groovy script that I tried to get the count of child nodes and wanted to print it.

 

 

Here is the XML:

 

<main xmlns="" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<People xmlns="">
<operation>A</operation>
<maincount>3</maincount>

 

<person xmlns="">
    <age>37</age>
    <gender>m</gender>
    <kids count='2' />
  </person>
  <person xmlns="">
    <age>28</age>
    <gender>f</gender>
    <kids count='0' />
  </person>
  <person xmlns="">
    <age>22</age>
    <gender>m</gender>
    <kids count='3' />
  </person>  
</people>
</main>

 

 

 

And Here is My Groovy Code:

 

import groovy.xml.*

 

/ Hello World in Groovy /
println("Hello world")
def str = '''\XML Format should be passed from Dell Boomi

 

def xml = new XmlSlurper(false, true).parseText(str)

 

 

 

def contactNodes = xml.Body.People.person

 

def ccount =0

 

 xml.person.findAll {
     it.maincount
 }.each {
     ccount++
     //println it.maincount.text()
     
 }
 
 println  'person count :' +ccount
 
 def count =0
 
 xml.children().each {
     count ++;
     
 }
 
  println count
    

Outcomes