1
votes

I have some elements that have the same tag name, but equal different values. The example below displays my parsing.

<Report>
<ReportHost name= 2.3.3.3><HostProperties>
<tag name="x"> Monday...</tag>
<tag name="z"> Linux.....</tag>

My issue is how do I capture the text after the string "x".. and "z" Currently I have

langs.Report.ReportHost.each{ReportHost->
${ReportHost.HostProperties.tag['@name']}"

But this is only grabbing x and z. What syntax do I need to grab the text after that which including Monday and Linux.

1
You need to grab the .text of each tag, you're specially asking for the attribute value. - Dave Newton

1 Answers

2
votes

This will print out the tag attribute list and then the node contents list:

langs.ReportHost.each { reportHost ->
  println "tag  = ${reportHost.HostProperties.tag['@name']}"
  println "cont = ${reportHost.HostProperties.tag*.text()}"
}

If you take your each further down the tree, then you can easily print them on one line

langs.ReportHost.HostProperties.tag.each { tag ->
  println "tag=${tag.@name} content=${tag.text()}"
}