Forum Discussion

Brickhead009's avatar
Brickhead009
New Contributor
13 years ago

Data-Driven Request Using XML File as Data Source

I see how to use Xpath to get repsonse data, using XML as the data source,
but it is not clear to me how to populate the request with data gathered from an XML file as the input data source.
Can you help?
  • Aaronliu's avatar
    Aaronliu
    Frequent Contributor
    the firstly you need to get correct response, next step to add property transfer step. in property transfer step, you'll see source and target. the source derive from steps you added and target is the destination. in both of them, you need to specify the data source using xpath expression. as for xpath, you would make sure of xpath assertion to help you declare namespace and copy that.
    however, I recommend that you use groovy script to parse XML and then retrieve data:

    def groovyUtil = new com.eviware.soapui.support.GroovyUtils(context)
    def xmlHolder = groovyUtil.getXmlHolder(messageExchange.responseContent) //if the script is a single step, using 'StepName#Response' in getXmlHoder('StepName#Response')
    xmlHolder.namespaces['ns1'] = 'http://www.soapui.org/forum' //if namespace existing, you need to declare first
    def val = xmlHolder.getNodeValue("//ns1:RootNode/ns2:Children") //xpath expression
    log.info val