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.
Highlighted
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
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
Let's start July with new challenges!

Create a script to change request body before sending it to the server for the TechCorner tag!


Scripts created in June:
- A script to generate a request body based on data from Datasource
- A script to go through all response nodes and check the value of the required field
- A Dispatching script to get responses based on the values in Request Body
- A script to add a new tag and assign it to all TestCases in a TestSuite
Top Kudoed Authors