Forum Discussion
Radford
10 years agoSuper Contributor
I'm not completely sure of what you are trying to do, but hopefully this will give you a start.
Using a Groovy test step there are a few ways to manipulate XML, I personally prefer the XmlSlurper. Here is an example of looping through the example JDBC result in your post:
import groovy.util.XmlSlurper
// Substitute your JDBC test name below
def responseAsXml = context.expand( '${JDBC Request#ResponseAsXml}' )
def Results = new XmlSlurper().parseText(responseAsXml)
Results.ResultSet.Row.each{ Row ->
// Normally wouldn't need the quotes around the XML element name,
// but we need them here because the element names contain a period.
log.info('Row ' + Row.@rowNumber + ' Id = ' + Row.'TRIP.ID'.text())
log.info('Row ' + Row.@rowNumber + ' Sequence = ' + Row.'TRIP.SEQUENCE_NUM'.text())
}
An alternative method, would be to use an XmlHolder, an example of using this to iterate through nodes can be found here.