Forum Discussion

richmon's avatar
richmon
Occasional Contributor
12 years ago

Looking for Strategies for Getting Attribute Data From CDATA

I get a response like this:

<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<LoadCompressedDeletedVehiclesResponse xmlns="http://tempuri.org/rpc/Gateway">
<LoadCompressedDeletedVehiclesResult>
<CompressedVehicles><![CDATA[<F
_0="vehicleid"
_1="vin"
_2="dateremoved">
<RS>
<R
_ID="zzz9876543210">
<VS>
<V
_0="501105711"
_1="1B3CB4HA4AD534674"
_2="5/30/2012 8:07:56 AM" />
<V
_0="501105711"
_1="1B3CB4HA4AD534674"
_2="9/18/2012 9:34:08 AM" />
<V
_0="501105712"
_1="1B3CC5FB7AN189889"
_2="8/24/2012 12:46:12 PM" />
</VS>
</R>
</RS>
</F>]]></CompressedVehicles>
<ErrorMessage/>
<InventoryResultType>OK</InventoryResultType>
<IsSuccess>true</IsSuccess>
</LoadCompressedDeletedVehiclesResult>
</LoadCompressedDeletedVehiclesResponse>
</soap:Body>
</soap:Envelope>


However, I've tried doing the double/triple property transfer but I get null values as there is no data between the elements. All of the data is stored in the attributes of a single element. This article doesn't handle these results.

I have also attempted to do a simple "Contains" check and creating some MSSQL that formats the string - but the root of the problem remains that the CDATA is an empty string and the real data is in the attributes. (Sloppy I know - but it is what I have to work with).

Please advise.
  • SiKing's avatar
    SiKing
    Community Expert
    In the linked article, in the third section it says:
    since now it is a standalone XML string it can be parsed as such and an XPath for this source will work just fine.
    emphasis mine. Have you tried that?
  • richmon's avatar
    richmon
    Occasional Contributor
    I tried using the SubmitListener.afterSubmit Event that is in section 6 of that page.

    When it works (which seems to be only 1/2 the time). I get an empty or NULL set value when using the first data transfer.

    I tried dumping the new content into an XML data store. I had minor success doing this - very minor. My store had the correct 1628 rows - but all values were empty.

    I'm flummoxed.
  • richmon's avatar
    richmon
    Occasional Contributor
    I've had more success since my last update. I was able to pull the attribute values using the aforemention event by stuffing the modified response content into an XML data source - thus bypassing the need to create the property transfer voodoo.

    Unfortunately that event only runs successfully 1/2 the time.

    Anyone have a better solution than

    if( submit.response == null )
    return

    def content = submit.response.responseContent
    content = content.replaceAll( "<!\\[CDATA\\[", "" )
    content = content.replaceAll( "]]>", "" )

    log.info( content )

    submit.response.responseContent = content
  • richmon's avatar
    richmon
    Occasional Contributor
    The code snippet above only seems to execute about 50% of the time.
    I added a 5 second delay step - hoping that would help - but I'm still at 50%.

    When it does run - it runs beautifully. But a 50% hit rate is quite poor. It there another way to perform the same activity?
  • Hi,

    The code snippet above only seems to execute about 50% of the time.
    I added a 5 second delay step - hoping that would help - but I'm still at 50%.


    The code used in the event handler should execute 100% of the time. What is happening during the 50% of time it doesn't work? Is there any errors appearing in the .log files in <soapui install>\bin folder?

    Does your response change every run where the CDATA is in different places or is the response static? There is a user in the pro forum (viewtopic.php?f=2&t=22210) that have reported having issues when the CDATA is in a certain location.

    Regards,
    Marcus
    SmartBear Support
  • richmon's avatar
    richmon
    Occasional Contributor
    The CDATA is always in the exact same place.

    The .log files are not showing an error.

    I have looked at the post you provided repeatedly. His circumstance is not mine.

    When I execute the test by itself - it nearly always executes. When it is executed in the suite (it is the first in the suite), it only hits about 50% of the time.
  • Hi!

    I'm a bit confused if the problem is related to the Event handler or the XML DataSoruce.
    Is the event handler executed at all times? One way test this is to add a
    log.info "Event"
    statement to the handler to see when it's called and not.

    Do you get any error related to the DataSoruce? Could you even send us you project for reproducing this? If you don't want to attach it here you could use our support form: http://www.soapui.org/Support/support-overview.html

    --
    Regards

    Erik
    SmartBear Sweden