Forum Discussion

krenevla's avatar
krenevla
Contributor
13 years ago

Property transfer - how to transfer "<" ?

Hello guys,

I need to describe my problem first

let's say I have in DB some Group object with one Child element so when I ask my server for info about this Group object, I got :

<group>
<element>
<description>element1</description>
</element>
</group>

I need to add another element to this group and I need to send original object + added another element as request. So it will looks as following

<group>
<element>
<description>element1</description>
</element>
<element>
<description>element2</description>
</element>

</group>

and now there is a problem. These elements and groups are not static so I have to ask server for their data and transfer whole object as property using "Transfer Child Nodes" function.
And I am not able to tell SoapUI, that if there is no existing target in defined XPath then it should create it.

I just can't set target as /group[1]/element[2] because original object contains just ../element[1].

So I thought I can add value "<element></element>" from defined properties to /group[1] so it will create second element object for me to which I can target second element. And there is a problem, if I transfer "<element></element>" then SoapUI replaces "<" with "&lt;". I tried to set property value as CDATA but it seems it ignores that as well.

so there are two ways how to solve it.
A - tell SoapUI to transfer "<" as "<" and not as "&lt;"
B - tell SoapUI to create missing XPath target
C - ?

Could someone help me out, please?
  • RJanecek wrote:
    use groovy script instead of property transfer


    could You please give me an small example on that?
  • RJanecek's avatar
    RJanecek
    Regular Contributor
    hm firstly you read your data from element
    def element = sql.firstrow("select" .....

    then you can convert this string to xml element: http://stackoverflow.com/questions/7296 ... de-in-java and working with these as element - append new node
    or you can do some operation with these string part1 = element.substring(0,element.lastIndexOf('/')-1)
    par1 = part1.concat("your new element")
    element .concat(part1 + element.substring(element.lastIndexOf('/'),element.lenght()))

    this code is just an idea how you can create element in groovy sccript
  • Hello,

    Groovy did the job for me, thanks for help. It's a pity there is missing function for adding elements in property transfer anyway.
    Because there is so little documentation around, I'll post my groovy here.

    It will add new element from other source to the request

    def groovyUtils = new com.eviware.soapui.support.GroovyUtils(context)
    def child = groovyUtils.getXmlHolder("getMeterAsset - LITE2#Response")
    def holder = groovyUtils.getXmlHolder("updateMeterAssetGroup - LITE#Request")
    def node = holder.getDomNode("//meterAssetGroup/meterAssets")
    node.appendChild(node.getOwnerDocument().importNode(child.getDomNode("//meterAsset"), true))
    holder.updateProperty()