jayamsrirama
12 years agoNew Contributor
[R]Need Help! in reading this XML/Saving it back with update
Friends,
Need your help for a groovy code which can
1) Load the below XML from the filepath,
2) replace a xml node value - <utility:serviceReferenceId> with a wild card character * value.
3) save the updated xml (full xml with updated node) to same file path or different folder file location.
Tried other options posted in the board but unable to figure out how to save the updated xml file back to same / different location.
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Header>
<_1:requestHeader xmlns:_1="http://www.google.com/utility/1/">
<_1:serviceReferenceId>ef639058aa94a60a-d3e52b992d1a3a0f</_1:serviceReferenceId>
<_1:functionalContext>
<_1:consumerName>CSA-EASConsumer</_1:consumerName>
<_1:userPrincipal>
<_1:userId>UNAUTHENTICATED</_1:userId>
<_1:orgRole>UNAUTHENTICATED</_1:orgRole>
<_1:appRole>UNAUTHENTICATED</_1:appRole>
</_1:userPrincipal>
<_1:target>
<_1:serviceName>ProfileLocator</_1:serviceName>
<_1:serviceOperation>TestProf</_1:serviceOperation>
</_1:target>
</_1:functionalContext>
</_1:requestHeader>
<KD4NS:KD4SoapHeaderV2 xmlns:KD4NS="http://www.ibm.com/KD4Soap">AFIAAgAkNzY1MzI2M2EtYzQ2Ni0zZmNkLWJjM2ItOGVkNTg1MDc3MmU1ACQ3ZDY1ODAzZS0xNTcxLTM2OTEtOWFmYS03MDdjZGI3NTI5YzIAFA==</KD4NS:KD4SoapHeaderV2>
</soapenv:Header>
<soapenv:Body>
<m:TestProfResponse xmlns:m="http://www.google.com/user/location/userprofile/1/">
<TestProfResponse xmlns="http://www.google.com/user/bi/1/" xmlns:prof="http://www.google.com/user/profile/1/" xmlns:addr="http://www.google.com/common/address/1/" xmlns:utility="http://www.google.com/utility/1/" xmlns:psnname="http://www.google.com/common/personname/1/">
<invocationOutcome>
<utility:serviceReferenceId>ef639058aa94a60a-d3e52b992d1a3a0f</utility:serviceReferenceId>
<utility:code>0</utility:code>
<utility:message>Successful</utility:message>
</invocationOutcome>
</TestProfResponse>
</m:TestProfResponse>
</soapenv:Body>
</soapenv:Envelope>
Tried the below code but couldnt get success saving the updated xml back to file / xml
def groovyUtils = new com.eviware.soapui.support.GroovyUtils( context )
def holder = groovyUtils.getXmlHolder("TestProf#Response")
holder.namespaces['utility']='http://www.google.com/utility/1/';
holder.namespaces['m']='http://www.google.com/user/location/userprofile/1/';
holder.namespaces['_1']='http://www.google.com/utility/1/';
holder.namespaces['soapenv']='http://schemas.xmlsoap.org/soap/envelope/';
holder.namespaces['addr']='http://www.google.com/common/address/1/';
holder.namespaces['ns1']='http://www.google.com/user/bi/1/';
holder.namespaces['prof']='http://www.google.com/user/profile/1/';
holder.namespaces['psnname']='http://www.google.com/common/personname/1/';
holder.namespaces['KD4NS']='http://www.ibm.com/KD4Soap'
for( item in holder.getNodeValue( "//utility:serviceReferenceId" ))
{
log.info "Item : [$item]"
holder.setNodeValue("//utility:serviceReferenceId","*")
holder.updateProperty(true)
}
log.info("Node Value: " + holder.getNodeValues( "//utility:serviceReferenceId"))
Need your help for a groovy code which can
1) Load the below XML from the filepath,
2) replace a xml node value - <utility:serviceReferenceId> with a wild card character * value.
3) save the updated xml (full xml with updated node) to same file path or different folder file location.
Tried other options posted in the board but unable to figure out how to save the updated xml file back to same / different location.
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Header>
<_1:requestHeader xmlns:_1="http://www.google.com/utility/1/">
<_1:serviceReferenceId>ef639058aa94a60a-d3e52b992d1a3a0f</_1:serviceReferenceId>
<_1:functionalContext>
<_1:consumerName>CSA-EASConsumer</_1:consumerName>
<_1:userPrincipal>
<_1:userId>UNAUTHENTICATED</_1:userId>
<_1:orgRole>UNAUTHENTICATED</_1:orgRole>
<_1:appRole>UNAUTHENTICATED</_1:appRole>
</_1:userPrincipal>
<_1:target>
<_1:serviceName>ProfileLocator</_1:serviceName>
<_1:serviceOperation>TestProf</_1:serviceOperation>
</_1:target>
</_1:functionalContext>
</_1:requestHeader>
<KD4NS:KD4SoapHeaderV2 xmlns:KD4NS="http://www.ibm.com/KD4Soap">AFIAAgAkNzY1MzI2M2EtYzQ2Ni0zZmNkLWJjM2ItOGVkNTg1MDc3MmU1ACQ3ZDY1ODAzZS0xNTcxLTM2OTEtOWFmYS03MDdjZGI3NTI5YzIAFA==</KD4NS:KD4SoapHeaderV2>
</soapenv:Header>
<soapenv:Body>
<m:TestProfResponse xmlns:m="http://www.google.com/user/location/userprofile/1/">
<TestProfResponse xmlns="http://www.google.com/user/bi/1/" xmlns:prof="http://www.google.com/user/profile/1/" xmlns:addr="http://www.google.com/common/address/1/" xmlns:utility="http://www.google.com/utility/1/" xmlns:psnname="http://www.google.com/common/personname/1/">
<invocationOutcome>
<utility:serviceReferenceId>ef639058aa94a60a-d3e52b992d1a3a0f</utility:serviceReferenceId>
<utility:code>0</utility:code>
<utility:message>Successful</utility:message>
</invocationOutcome>
</TestProfResponse>
</m:TestProfResponse>
</soapenv:Body>
</soapenv:Envelope>
Tried the below code but couldnt get success saving the updated xml back to file / xml
def groovyUtils = new com.eviware.soapui.support.GroovyUtils( context )
def holder = groovyUtils.getXmlHolder("TestProf#Response")
holder.namespaces['utility']='http://www.google.com/utility/1/';
holder.namespaces['m']='http://www.google.com/user/location/userprofile/1/';
holder.namespaces['_1']='http://www.google.com/utility/1/';
holder.namespaces['soapenv']='http://schemas.xmlsoap.org/soap/envelope/';
holder.namespaces['addr']='http://www.google.com/common/address/1/';
holder.namespaces['ns1']='http://www.google.com/user/bi/1/';
holder.namespaces['prof']='http://www.google.com/user/profile/1/';
holder.namespaces['psnname']='http://www.google.com/common/personname/1/';
holder.namespaces['KD4NS']='http://www.ibm.com/KD4Soap'
for( item in holder.getNodeValue( "//utility:serviceReferenceId" ))
{
log.info "Item : [$item]"
holder.setNodeValue("//utility:serviceReferenceId","*")
holder.updateProperty(true)
}
log.info("Node Value: " + holder.getNodeValues( "//utility:serviceReferenceId"))