Forum Discussion

novice's avatar
novice
New Contributor
14 years ago

How to truncate "<![CDATA[" from the request

Hi All,

I have been trying to dynamically add/ modify property in the request.xml which should look like this:

<dat:property xmlns:nsPROP="http://messaging.domain.net/datatypes" nsPROP:name="P1" nsPROP:type="boolean">true</dat:property>

<property xmlns:nsPROP="http://messaging.domain.net/datatypes" nsPROP:name="P2" nsPROP:type="int">0</property>

<property xmlns:nsPROP="http://messaging.domain.net/datatypes" nsPROP:name="P3" nsPROP:type="string">Magicsdfdsf</property>


and for that I am using "Properties" table as a test step
which has for example:
P1's value -- <dat:property xmlns:nsPROP="http://messaging.domain.net/datatypes" nsPROP:name="P1" nsPROP:type="boolean">true</dat:property>

P2's value -- <property xmlns:nsPROP="http://messaging.domain.net/datatypes" nsPROP:name="P2" nsPROP:type="int">0</property>

P3's value -- <property xmlns:nsPROP="http://messaging.domain.net/datatypes" nsPROP:name="P3" nsPROP:type="string">Magicsdfdsf</property>


and then fetching the particular property by using :
def P1 = testRunner.testCase.testSteps["Properties"].getPropertyValue( "P1" )

and using this in:
request1.setNodeValue("//dat:properties", "${P1}${P2}${P3}");

so that it should look like this -
<dat:properties>
<dat:property xmlns:nsPROP="http://messaging.domain.net/datatypes" nsPROP:name="P1" nsPROP:type="boolean">true</dat:property>

<property xmlns:nsPROP="http://messaging.domain.net/datatypes" nsPROP:name="P2" nsPROP:type="int">0</property>

<property xmlns:nsPROP="http://messaging.domain.net/datatypes" nsPROP:name="P3" nsPROP:type="string">Magicsdfdsf</property>

</dat:properties>

But my problem is I am getting this but embedded in "<![CDATA[ ]]> " like this -

<dat:properties><![CDATA[<dat:property xmlns:nsPROP="http://messaging.domain.net/datatypes" nsPROP:name="P1" nsPROP:type="boolean">true</dat:property> <property xmlns:nsPROP="http://messaging.domain.net/datatypes" nsPROP:name="P2" nsPROP:type="int">0</property> <property xmlns:nsPROP="http://messaging.domain.net/datatypes" nsPROP:name="P3" nsPROP:type="string">Magicsdfdsf</property>]]></dat:properties>

Please help me, how I can avoid or truncate "<![CDATA[ ]]> " ?


Thanks in advance.

Regards,
Novice.

1 Reply

  • novice's avatar
    novice
    New Contributor
    Can we do something like this -
    def groovyUtils = new com.eviware.soapui.support.GroovyUtils( context );
    def request1 = groovyUtils.getXmlHolder("getPermissions#Request");
    def P1 = testRunner.testCase.testSteps["Properties"].getPropertyValue( "P1" )
    def P2 = testRunner.testCase.testSteps["Properties"].getPropertyValue( "P2" )
    def P3 = testRunner.testCase.testSteps["Properties"].getPropertyValue( "P3" )
    request1.setNodeValue("//dat:properties", "\n${P1}\n${P2}\n${P3}\n");

    def requestContent = request1.requestContent
    log.info("old request without CDATA &colon; " + request1.requestContent);
    requestContent = requestContent.replaceAll("<!\\[CDATA\\[","")
    requestContent = requestContent.replaceAll("]]>","")
    log.info("New request without CDATA &colon; " + request1.requestContent);
    request1.requestContent = requestContent

    I got the hint from here- http://www.soapui.org/Functional-Testin ... cdata.html and Pradeep bishnoi's blog.

    But still can't get it working. see error below.

    groovy.lang.MissingMethodException: No signature of method:
    com.eviware.soapui.support.XmlHolder.replaceAll() is applicable for argument types: (java.lang.String,java.lang.String) values: [<!\[CDATA\[,]

    Any help, what's going wrong?