Forum Discussion
Hi,
Ok, so if I may suggest the use of XMLSlurper, which is built into Groovy so requires no imports and is quote neat. Then if we put your XML snippet (similar typed in by me) into a file /work/SoapUI Forum/soapy.xml:
<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope xmlns:soap="http://www.w3.org/2001/12/soap-envelope">
<soap:Header/>
<soap:Body>
<tem:Add xmlns:tem="http://tempuri.org">
<tem:intA>5</tem:intA>
<tem:intB>7</tem:intB>
</tem:Add>
</soap:Body>
</soap:Envelope>
Then, the following Groovy script allows you to parse the XML from file, update the values of intA and intB and save the resulting XML back to the same file:
import groovy.xml.XmlUtil
def xmlFromFile = new File('/work/SoapUI Forum/soapy.xml')
def envelopeNode = new XmlSlurper().parseText(xmlFromFile.getText())
envelopeNode.Body.Add.intA=5
envelopeNode.Body.Add.intB=7
//Just to print it out
XmlUtil xmlUtil = new XmlUtil()
log.info xmlUtil.serialize(envelopeNode)
//To update the file with updated XML
xmlUtil.serialize(envelopeNode, new FileWriter(xmlFromFile))
Is this what you needed?
Cheers,
Rup
- vikram_966910 years agoOccasional Contributor
Thanks Rup!!
This is what I was looking for. But how to parameterize both xpath and and node value. Lets say, I am taking this xpath (envelopeNode.Body.Add.intA) as a input parameter from excel sheet and then modifying the value to '20'.
def sIntA=envelopeNode.Body.Add.intA // Lets say, this value is taken from excel sheet (I have a code to get the value from excel sheet)
My aim is to get the Node's xpath from excel sheet, get the Node's value from excel sheet, update the xml with this node and save updated xml in a different folder.
Please suggest.
- rupert_anderson10 years agoValued Contributor
Hi,
Thats ok.
I think I now get what you are after i.e. a way to pass the actual (XPath) query in as a String paramter, but before having a go at that, can I ask if you actually just want a way to parameterise and populate SOAP requests from your spreadsheet of values e.g. data-driven testing? If this is the case I can potentially explain an easier way to do this in SoapUI using your spreadsheet.
Cheers,
Rup- vikram_966910 years agoOccasional Contributor
Yes Rup. I am actually looking for data driven testing. I am trying to use external xml stored on local disc. I will update the node values using xpath. After updating the xml, I will save it in different folder and at the end I will upload both request xml and response xml to the test case in ALM. It helps me keeping track of request and response used for specific test case.
Please let me know if you have any easier way to do this.
Really appreciate your help. Thanks!
Cheers,
Vikram
Related Content
Recent Discussions
- 15 years ago