Ask a Question

how do build a string of same nodes from JDBC response


how do build a string of same nodes from JDBC response

I want to create a string of all the nodes that are the same. Using my example below, I want a string of all nodes that have more than one same name. For example, using the JDBC response below, I would want to create two strings. One for TRIP.ID and another string for all TRIP.SEQUENCE_NUM


Can anyone guide me through this ?

<ResultSet fetchSize="0">
<Row rowNumber="1">
<Row rowNumber="2">
<Row rowNumber="3">
<Row rowNumber="4">
<Row rowNumber="5">
<Row rowNumber="6">

Super Contributor

Re: how do build a string of same nodes from JDBC response

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.'Row ' + Row.@rowNumber + ' Id = ' + Row.'TRIP.ID'.text())'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.

Showing results for 
Search instead for 
Did you mean: