cancel
Showing results for 
Search instead for 
Did you mean: 

Parsing XML from response

New Contributor

Parsing XML from response

Hi,

First of all, i'm a compete noob to soapui. I've looked extensively trough the available explanations here http://www.soapui.org/scripting---prope ... properties and here http://www.robert-nemet.com/2011/11/gro ... 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:body>
      <ns0:contractrekeningen>
      <ns0:contractrekening>
      <ns0:contractrekeningIdentificatie>200000000538</ns0:contractrekeningIdentificatie>
      <ns0:BTWcategorie>Energie Debiteur 21%</ns0:BTWcategorie>
      <ns0:communicatievoorkeur>Individueel Brief</ns0:communicatievoorkeur>
      <ns0:overeenkomsten>
      <ns0:overeenkomst>
      <ns0:overeenkomstIdentificatie>3000077614</ns0:overeenkomstIdentificatie>
      <ns0:begindatum>2013-10-01+02:00</ns0:begindatum>
      <ns0:productgroep>ELK</ns0:productgroep>
      <ns0:locatie>
      <ns0:locatieIdentificatie>5000018162</ns0:locatieIdentificatie>
      <ns0:adres>
      <ns0:postcode>3561CV</ns0:postcode>
      <ns0:huisnummer>10</ns0:huisnummer>
      <ns0:straatnaam>Euterpedreef</ns0:straatnaam>
      <ns0:plaatsnaam>UTRECHT</ns0:plaatsnaam>
      </ns0:adres>
      <ns0:aansluitingen>
      <ns0:aansluiting>
      <ns0:aansluitingIdentificatie>871687400009970233</ns0:aansluitingIdentificatie>

    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 com.eviware.soapui.support.GroovyUtils( context )
      def holder = groovyUtils.getXmlHolder("Properties#response")
      log.info holder.getNodeValue("//ns0:contractrekeningIdentificatie")
      log.info 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:
      contractrekening;adres;aansluitingIdentificatie
2 REPLIES 2
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.


Regards,
Rao.
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 com.eviware.soapui.support.GroovyUtils( context )
def holder = groovyUtils.getXmlHolder( "overeenkomstOpvragen - Request 1#Response" )
// define namespace
holder.namespaces["ns"] = "http://www.stedin.net/interfaces/SiteCoreAdapter/services/contractrekeningOvereenkomstOpvragenResponse/1"
// loop item nodes in response message
for( item in holder.getNodeValues( "//ns:aansluitingIdentificatie" ))
log.info "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:
Announcements