Showing results for 
Search instead for 
Did you mean: 

Parsing XML from response

New Contributor

Parsing XML from response


First of all, i'm a compete noob to soapui. I've looked extensively trough the available explanations here ... properties and here ... oapui.html to solve my problem to no avail.
Can anyone provide me with a step by step instructions to do the following

  1. i send a soap request

  2. from the response i get i want to parse some of the node data in a text file or show it in the script log.

  3. What i've tried so far, using some of the info on the above mentioned pages:

    1. i've made a testcase with the request

    2. Part of the rsponse i get:
      <ns0:BTWcategorie>Energie Debiteur 21%</ns0:BTWcategorie>
      <ns0:communicatievoorkeur>Individueel Brief</ns0:communicatievoorkeur>

    3. then added a test step properties and created the property 'response'

    4. then added a test step Groovy Script (retrieved from the XML PArsing instructione site)
      def groovyUtils = new context )
      def holder = groovyUtils.getXmlHolder("Properties#response") holder.getNodeValue("//ns0:contractrekeningIdentificatie") holder['//ns0:contractrekeningIdentificatie']

    5. I ger an error: Unexpected end of file after null
      Am I on the right track here? Can anyone give a step by step explanation how to achieve this?
      Ideally I would like to create the output of all nodes in an structured way so i can paste it into excel. But I would already be very glad if i can extract all the ns0:aansluitingIdentificatie></ns0:aansluitingIdentificatie values from the response. But if i can also get for example the 'contractrekening', the 'adres' associated with this contractrekening and the 'aansluitingIdentificatie' associated with this 'contractrekening' etc etc this would be perfect!
      for example:
Community Hero

Re: Parsing XML from response

Welcome to the forum.

You would want to do the following steps in the test case:
1. Test Request
2. Groovy Script

Once you get the response, you can do the stuff using groovy script and not really required properties step. For this, you need to access the response of previous step in the groovy script. And navigate thru values using getNodeValue of given element's xpath. For this you can search for Soapui tips where it has examples.

Also you do not have to manually copy the output to excel. You may be able to do it using Apache POI. You can google for it and it has good samples as well.

New Contributor

Re: Parsing XML from response

Thanks. I'v e now partly achieved what I want. I can extract the <ns0:aansluitingIdentificatie from the xml file using the code:
def groovyUtils = new context )
def holder = groovyUtils.getXmlHolder( "overeenkomstOpvragen - Request 1#Response" )
// define namespace
holder.namespaces["ns"] = ""
// loop item nodes in response message
for( item in holder.getNodeValues( "//ns:aansluitingIdentificatie" )) "EAN : $item"

I will need a little more help because i'm a tester who doen't really know how to program/script.
What code should I add to create a line that lists ns0:aansluitingIdentificatie, ns0:productgroep, ns0:postcode, ns0:huisnummer, <ns0:straatnaam, <ns0:plaatsnaam>

Also, you mentioned the apache poi. I checked the website but this also goes a little over my head. Should I firts install the apache POI classes in the SOAPUI folder or does soapui already include this functionality?
New Here?
Join us and watch the welcome video: