cos2912
7 years agoNew Contributor
How to get the entire subtree from a xml response with xpath
How can I get a section of a REST response in xml to use in a REST request. I use the Property Transfer step with Property=ResponseAsXml and Path language=XPath. What xpath should I write if I want...
- 7 years ago
No, the ?. is real Groovy code, you don't need to change it.
You will want to do something like this Groovy script, which acts like a Property Transfer step.
import groovy.xml.StreamingMarkupBuilder
String xml = testRunner.testCase.getTestStepByName('someEarlierTestStep')
.httpRequest.response.responseContent
String innerXml = new XmlSlurper().parseText(xml)
.'b'
?.find { b -> b.'@k' == 'zzz' }
?.with { node -> new StreamingMarkupBuilder().bindNode(node) } as String
testRunner.testCase.setPropertyValue("InnerXML", innerXml)