Forum Discussion

max1965's avatar
max1965
Contributor
13 years ago

extract value from xml

I try to apply the suggestion that I have from the forum to the following XML response, but I'm not able to extract the interested value.

First case:

I need to extract the result value (pending) from the following response:

<env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/">
<env:Header/>
<env:Body>
<ns2:requestResponse xmlns:ns2="http://tempuri.org/provisioning.xsd">
<outputMsg>&lt;spml:statusResponse xmlns:spml='urn:oasis:names:tc:SPML:1:0'

xmlns:dsml='urn:oasis:names:tc:DSML:2:0:core' requestID='IDM-20130307092850677'

result='urn:oasis:names:tc:SPML:1:0#pending'>
&lt;/spml:statusResponse></outputMsg>
</ns2:requestResponse>
</env:Body>
</env:Envelope>

Second case:

I need to extract the errorCode value (1000) to the following response:

<env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/">
<env:Header/>
<env:Body>
<ns2:requestResponse xmlns:ns2="http://tempuri.org/provisioning.xsd">
<outputMsg><![CDATA[<spml:statusResponse xmlns:spml='urn:oasis:names:tc:SPML:1:0'

xmlns:dsml='urn:oasis:names:tc:DSML:2:0:core' requestID='IDM-20130307092850677'

result='urn:oasis:names:tc:SPML:1:0#success'>
<spml:searchResponse requestID='IDM-20130307092850677'

result='urn:oasis:names:tc:SPML:1:0#success'>
<spml:operationalAttributes>
<dsml:attr name='errorCode'>
<dsml:value>1000</dsml:value>
</dsml:attr>
<dsml:attr name='errorMessage'>
<dsml:value>The operation is successfully completed</dsml:value>
</dsml:attr>
</spml:operationalAttributes>
<spml:searchResultEntry>
<spml:identifier type='urn:oasis:names:tc:SPML:1:0#GUID'>
<spml:id>00498800</spml:id>
</spml:identifier>
<spml:attributes>
<dsml:attr name='accessState'>
<dsml:value>0</dsml:value>
</dsml:attr>
<dsml:attr name='surname'>
<dsml:value>TERMINI</dsml:value>
</dsml:attr>
<dsml:attr name='metaFunctionalProfileDomain'>
<dsml:value>PR2HIGH@MS</dsml:value>
</dsml:attr>
<dsml:attr name='userProfile'>
<dsml:value>default</dsml:value>
</dsml:attr>
<dsml:attr name='strongAuth'>
<dsml:value>Y</dsml:value>
</dsml:attr>
<dsml:attr name='userType'>
<dsml:value>0</dsml:value>
</dsml:attr>
<dsml:attr name='password'>
<dsml:value>UMc7Czl6/1eZE</dsml:value>
</dsml:attr>
<dsml:attr name='container'>
<dsml:value>MS</dsml:value>
</dsml:attr>
<dsml:attr name='employeeId'>
<dsml:value>00498800</dsml:value>
</dsml:attr>
<dsml:attr name='administrativeState'>
<dsml:value>Active</dsml:value>
</dsml:attr>
</spml:attributes>
</spml:searchResultEntry>
</spml:searchResponse>
</spml:statusResponse>]]></outputMsg>
</ns2:requestResponse>
</env:Body>
</env:Envelope>


Someone could help me ? Thanls.

5 Replies

  • For the first case I write the following groovy script:

    def groovyUtils = new com.eviware.soapui.support.GroovyUtils( context )
    def response = context.expand( '${statusRequestPending#Response}' )
    def holder = groovyUtils.getXmlHolder( response )
    def cdata = holder.getDomNode('//outputMsg/text()').nodeValue
    log.info cdata
    def holder2 = groovyUtils.getXmlHolder( cdata )
    def status = holder2.getDomNode('//spml:statusResponse//result=/text()').nodeValue
    log.info status
    if ( status == "success" )
    {
    log.info("SearchUser - wrong status: $status")
    testRunner.fail( "status" )
    }

    but the status variable return "false".
  • For the first case, I modify the script:

    def groovyUtils = new com.eviware.soapui.support.GroovyUtils( context )
    def response = context.expand( '${statusRequestPending#Response}' )
    def holder = groovyUtils.getXmlHolder( response )
    def cdata = holder.getDomNode('//outputMsg/text()').nodeValue
    def holder2 = groovyUtils.getXmlHolder( cdata )
    xmlBody = new XmlSlurper().parseText(holder2.getXml())
    status = xmlBody.@result
    log.info status
    if ( status == "pending" )
    {
    log.info("SearchUser - wrong status: $status")
    testRunner.fail( "status" )
    }

    Now the status variable is set to "urn:oasis:names:tc:SPML:1:0#pending"; how can extract only the value after the "#" character ?
  • add this

    status = (status .indexOf('#') >= 0) ? status [status .lastIndexOf('#') + 1 .. -1] : status

    after
    status = xmlBody.@result