Forum Discussion

TesterNo1's avatar
TesterNo1
Contributor
9 years ago
Solved

how to replace entire parent node in request xml

 Hi all,

 

I have multiple tags in a request.i need to replace the root tag<Testing Root> so  i dont have to do it tag by tag.Does anyone have idea on how to do this ?

 

 

<Testing Root>

<Sub Test 1>

<Sub Test 2>
<Sub Test 3>

</Testing Root>

 

thanks you 

 

  • thank you rao.

     

    I treid for long but figured out that i can dom object. Below code wored.

     


    def groovyUtils = new com.eviware.soapui.support.GroovyUtils(context);
    def namespace = "http://pos.odc.vzwcorp.com";
    def holder = groovyUtils.getXmlHolder("Get Edge Installment Device#Request");
    def npanxxholder =groovyUtils.getXmlHolder("Npanxx Lookup Call#Request");
    holder.namespaces["ns1"] = namespace;
    npanxxholder.namespaces["ns1"] = namespace;

    use (groovy.xml.dom.DOMCategory){

    for( node in npanxxholder.getDomNodes( "//ns1:orderKeyInfo")) {
    node.children().each { child ->
    childname=child.name()
    childtext=child.text()
    log.info child.name()
    log.info child.text()
    //log.info "//ns1:"+"$childname"
    holder.setNodeValue("//ns1:"+"$childname",child.text())
    holder.updateProperty()
    }
    }

    }

4 Replies

  • nmrao's avatar
    nmrao
    Champion Level 3
    It would be helpful if you provide the context, and the use case that you are trying to achieve.
    • TesterNo1's avatar
      TesterNo1
      Contributor
      Rao,I need to transfer node and child nodes from one api to other using groovy.all child nodes inside the main node are common meaning they are both same tags.only values needs to be replaced/ transferred
      • nmrao's avatar
        nmrao
        Champion Level 3
        Well. If you want to provide sample source and target and datamapping between the two, would be great.