cancel
Showing results for 
Search instead for 
Did you mean: 

How to add nodes for soapUI request,useing groovy?

Highlighted
New Contributor

How to add nodes for soapUI request,useing groovy?

Actual Requset.

<root xmlns:foo="http://www.foo.org/" xmlns:bar="http://www.bar.org">
	<actors>
		<actor>Christian Bale</actor>
		<actor>Liam Neeson</actor>
		<actor>Michael Caine</actor>
	</actors>
	<foo:singers>
		<foo:singer>Tom Waits</foo:singer>
		<foo:singer>B.B. King</foo:singer>
		<foo:singer>Ray Charles</foo:singer>
	</foo:singers>
</root>

Expected request

<root xmlns:foo="http://www.foo.org/" xmlns:bar="http://www.bar.org">
	<actors>
		<actor >Christian Bale</actor>
		<actor >Liam Neeson</actor>
		<actor >Michael Caine</actor>
	</actors>
	<foo:singers>
		<foo:singer>Tom Waits</foo:singer>
		<foo:singer>B.B. King</foo:singer>
		<foo:singer>Ray Charles</foo:singer>
	</foo:singers>
<foo:singers>
<foo:singer >Tom Waits</foo:singer>
<foo:singer >Ray Charles</foo:singer>
</foo:singers> 
</root>

 

2 REPLIES 2
Highlighted
Community Leader

@praneeth12 :

 

You can refer below link to modify/create XML at runtime using groovy script.

 

https://community.smartbear.com/t5/SoapUI-Pro/TechCorner-Challenge-4-How-to-Generate-a-Request-Body-...


Click "Accept as Solution" if my answer has helped,
Remember to give "Kudos" 🙂 ↓↓↓↓↓



Thanks and Regards,
Himanshu Tayal
Highlighted
New Contributor

Thank you for your reply.

 

I tried with below code

addNewNode = """         """" // new node in parseText format 

def root8 = new XmlParser().parseText( requestXML ) // converted request xml into parseText


for (item in root8){
for(test1 in item){
nodelist = test1.value()
nodelist.add(addNewNode)
}
}
log.info root8
String outxml = groovy.xml.XmlUtil.serialize(root8)

I am able to append node but the problem was when i am serializing  data in xml format, new node is on parsetext format.How to serialize new node.

Any one help me on this..

New Here?
Join us and watch the welcome video:
Announcements
Top Kudoed Authors