Forum Discussion

cos2912's avatar
cos2912
New Contributor
7 years ago

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...
  • JHunt's avatar
    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)