cancel
Showing results for 
Search instead for 
Did you mean: 

how to replace entire parent node in request xml

SOLVED
Highlighted
Contributor

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 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Contributor

Re: how to replace entire parent node in request xml

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()
}
}

}

View solution in original post

4 REPLIES 4
Highlighted
Community Hero

Re: how to replace entire parent node in request xml

It would be helpful if you provide the context, and the use case that you are trying to achieve.


Regards,
Rao.
Contributor

Re: how to replace entire parent node in request xml

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
Highlighted
Community Hero

Re: how to replace entire parent node in request xml

Well. If you want to provide sample source and target and datamapping between the two, would be great.


Regards,
Rao.
Highlighted
Contributor

Re: how to replace entire parent node in request xml

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()
}
}

}

View solution in original post

New Here?
Join us and watch the welcome video:
Announcements
Script Wanted
Check out this week's challenge!

Create a script to generate an email when an assertion fails for the TechCorner tag!


Scripts created in July:
- A script to change the request body before sending it to the server