Forum Discussion

Nikolaj's avatar
Nikolaj
Occasional Contributor
12 years ago

How get multiple value from difficult response

Hi All,

I have a little problem. My response is:

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Body>
<GetDerResponse xmlns="http://www.test.com/Services">
<GetDerResult xmlns:a="http://schemas.data.org/2004/07/Data" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<a:Derivative>
<Code xmlns="http://www.test.com/Data">SL501</Code>
<Id xmlns="http://www.test.com/Data">90941</Id>
<Name xmlns="http://www.test.com/Data">SL-50 TE</Name>
<a:DeliveryCharge i:nil="true"/>
<a:LongName>SL-50 TE</a:LongName>
<a:Model>
<Code xmlns="http://www.test.com/Data">AS2</Code>
<Id xmlns="http://www.test.com/Data">0</Id>
<Name xmlns="http://www.test.com/Data">AR SL-50</Name>
<a:LongName>AR SL-50</a:LongName>
<a:Manufacturer>
<Code xmlns="http://www.test.com/Data"/>
<Id xmlns="http://www.test.com/Data">0</Id>
<Name xmlns="http://www.test.com/Data">Ariston</Name>
</a:Manufacturer>
</a:Model>
</a:Derivative>
<a:Derivative>
<Code xmlns="http://www.test.com/Data">SL502</Code>
<Id xmlns="http://www.test.com/Data">90942</Id>
<Name xmlns="http://www.test.com/Data">SL-50 TE-HA</Name>
<a:DeliveryCharge i:nil="true"/>
<a:LongName>SL-50 TE-HA</a:LongName>
<a:Model>
<Code xmlns="http://www.test.com/Data">AS2</Code>
<Id xmlns="http://www.test.com/Data">0</Id>
<Name xmlns="http://www.test.com/Data">AR SL-50</Name>
<a:LongName>AR SL-50</a:LongName>
<a:Manufacturer>
<Code xmlns="http://www.test.com/Data"/>
<Id xmlns="http://www.test.com/Data">0</Id>
<Name xmlns="http://www.test.com/Data">Ariston</Name>
</a:Manufacturer>
</a:Model>
</a:Derivative>


I need to get the values ​​of Derivative Name lines only. I use groovy script:

def groovyUtils = new com.eviware.soapui.support.GroovyUtils( context )
def holder = groovyUtils.getXmlHolder("MyTestStepName#Response")
for (h in holder["//*:Name"]){
log.info(h)
}


Groovy script result is: SL-50 TE, AR SL-50, Ariston, SL-50 TE-HA, AR SL-50, Ariston

But I need that result should be: SL-50 TE, SL-50 TE-HA only

Please advice how I do it better.

Any suggestion is appreciated.
Thanks in advance.

1 Reply

  • Aaronliu's avatar
    Aaronliu
    Frequent Contributor
    this should be easy to fetch the designated values from xml:

    def groovyUtils = new com.eviware.soapui.support.GroovyUtils( context )
    def holder = groovyUtils.getXmlHolder("MyTestStepName#Response")

    declare namespace['a'] = "http://schemas.data.org/2004/07/Data"
    declare namespace['b'] = "http://www.test.com/Data"
    def count = holder.getNodeValue ("count(//a:GetDerResult/a:Derivative)")
    def counter = count.toInteger()
    if (counter !=0){
    (0..<counter).each{
    def name = holder.getNodeValue("//a:GetDerResult/a:Derivative["+it+"]/b:Name")
    log.info name
    }
    }



    thanks,
    Aaron