Getting the value of child node in xml using groovy -


how parse value of profile in below xml using groovy?

<books>         <book>                 <profile>science</profile>                 <extension>.png</extension>                 <length>1920</length>                 <width>1080</width>         </book>         <book>                 <profile>english</profile>                 <extension>.png</extension>                 <length>640</length>                 <width>460</width>         </book>  </books> 

i have tried:

def bookxml = new xmlslurper().parsetext(booktext) def profile = bookxml.book.findall { it.profile }  

but not working expected.

it should work - if syntax corrected parsetext instead of parsexml - profiles found.

catch sample:

def bookxml = '''<books>         <book>                 <profile>science</profile>                 <extension>.png</extension>                 <length>1920</length>                 <width>1080</width>         </book>         <book>                 <profile>english</profile>                 <extension>.png</extension>                 <length>640</length>                 <width>460</width>         </book>  </books>'''  def bookxml = new xmlslurper().parsetext(bookxml) bookxml.book.findall { it.profile }.each { println it.profile.text() } 

Comments