Ask a Question

How to retrieve Node Tree when child value matches text

Occasional Contributor

How to retrieve Node Tree when child value matches text

Dear Smartbear community,


it has been a while since I have been at the coal face however I have searched far and wide for a response yet I can't quite find a solution to my problem.  I hope someone can help.  I am using groovy to parse an API call response in xml.  An example is below:


<runDuration>0 days 00:47:14</runDuration>


I essentially want to pull out the <name> and <stepName> for the 'FAILED' steps (i.e. STEP_THREE).  Or ALL <stepNames> that meet the search string, like 'RUNNING' or 'FAILED'


So it might print line "Job " + + " Step " + node.stepname.text() + " Failed."

"Job JOB_NAME Step STEP_THREE Failed."


As I say it has been a while since I have needed to solve these problems and I am a bit rusty.  I am a big flumoxed and any help would be much appreciated.

Occasional Contributor

Thanks to some valuable contributions from other sites, I managed to find a solution.  It was fairly easy in the end stiching some ideas from those posts.  I have put it here in case anyone would like to make use of it.


import groovy.util.*
import java.text.SimpleDateFormat

def sdfDateFormat = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss")

//Parse XML content in the response
def completedResponse = context.expand( '${ListCompletedStreams#Response}' )
def parsedcompletedResponse = new XmlSlurper().parseText(completedResponse)

//Loop over each Job Entry { jobEntry ->

//Loop over every steo entry and pull out only those steps that fail. Find the parent Job Name and other parent properties.
jobEntry.steps.stepEntry.each { stepEntry ->
if (stepEntry.stepState.text() == "FAILED" ) {

def strJobEntryRunDate = Date.parse("yyyy-MM-dd'T'HH:mm:ss", "${jobEntry.runDate.text()}") "\tJob Stream : ${} starting at " + sdfDateFormat.format(strJobEntryRunDate) + " has a failed Job Step." "\tJob Step: ${stepEntry.stepName.text()} failed after ${jobEntry.runDuration.text()} minutes."

return null

Showing results for 
Search instead for 
Did you mean: