I want to retrieve the elements of <logs>
as array of String
and I am trying the following:
import groovy.util.XmlSlurper
def payload = '''<logs>
<log>
<text>LOG 1</text>
<timestamp>2017-05-18T16:20:00.000</timestamp>
</log>
<log>
<text>LOG 2</text>
<timestamp>2017-05-18T16:20:00.000</timestamp>
</log>
</logs>'''
def logs = new XmlSlurper().parseText(payload)
def result = []
logs.log.each{
result.add(it)
}
result
However, I am getting the values, but I would like to get the whole node as text, more or less this:
[<log>
<text>LOG 1</text>
<timestamp>2017-05-18T16:20:00.000</timestamp>
</log>,
<log>
<text>LOG 2</text>
<timestamp>2017-05-18T16:20:00.000</timestamp>
</log>]
Is this at all possible with XmlSlurper
or should I use some String operations?