blatec
12 years agoOccasional Contributor
Namespace declaration lost
Hi,
I have to add a new node to the request XML using groovy
I always did it in the same way es below:
But in this case, the namespace declaration for "ns5" is removed......
This is a part of the XML, before i manipulated it with the script:
And this is the XML after the manipulation....now "xmlns:ns5="http://www.uniquare.com/ubml/db/loandetails/xso/dol/std" is missing..
Any ideas why this happens??
best regards
Horst
I have to add a new node to the request XML using groovy
I always did it in the same way es below:
def request = testRunner.testCase.getPropertyValue("Response_readAndUpdateAdvisory")
import groovy.xml.MarkupBuilder
def records = new XmlParser().parseText((request.value).toString())
def rootNode = records.'**'.find{it.name() == 'message'}
// new node which have to be inserted
Node urlset = new XmlParser().parseText('<approverList createdById="UBMLTechUser" createdAt="2013-05-15T07:19:30.504+03:00" lastChangedById="UBMLTechUser" lastChangedAt="2013-05-15T07:19:30.504+03:00" optimisticLockAttribute="0" mandatorKey="002 848" deleted="false" id="203D0000040515071905"><name>KAR_Approver</name><userId/><approverTypeKeySle>001</approverTypeKeySle></approverList>')
def childNode= rootNode.children()
// the new node is added to the end
rootNode.append(urlset)
// second part add to approval loanRequestId
// getloanrequestId
def loanRequestId = ""
def requestNode = records.'**'.find{it.name() == 'loanRequest'}
loanRequestId = requestNode.attribute("id")
// add loanrequest to approval
def approvalNode = records.'**'.find{it.name() == 'approverList'}
def newNode = new Node(null, 'loanRequestId', loanRequestId)
approvalNode.appendNode(newNode)
log.info approvalNode.toString()
def writer = new StringWriter()
new XmlNodePrinter(new PrintWriter(writer)).print(records)
def xmlString = com.eviware.soapui.support.xml.XmlUtils.prettyPrintXml(writer.toString())
testRunner.testCase.setPropertyValue("Response_readAndUpdateAdvisory", xmlString )
But in this case, the namespace declaration for "ns5" is removed......
This is a part of the XML, before i manipulated it with the script:
<conditionList xsi:type="ns5:DbScheduledPaymentXso" id="09xZ3iNcfP3sOT1xzP30" deleted="false" mandatorKey="002 848" optimisticLockAttribute="0" lastChangedAt="2013-06-19T12:57:07.901+02:00" lastChangedById="UBMLTechUser" createdAt="2013-06-19T12:57:07.901+02:00" createdById="UBMLTechUser" xmlns:ns5="http://www.uniquare.com/ubml/db/loandetails/xso/dol/std" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<loanContractId>204A0000050619125703</loanContractId>
<conditionTypeSle>004</conditionTypeSle>
<validFrom>2015-02-28+01:00</validFrom>
<validTo>2015-02-28+01:00</validTo>
<conditionPeriodSle>005</conditionPeriodSle>
<isAnnounced>false</isAnnounced>
<scheduledPaymentTypeSle>002</scheduledPaymentTypeSle>
<percentage>3</percentage>
<amount>100</amount>
<calculationModeSle>002</calculationModeSle>
</conditionList>
And this is the XML after the manipulation....now "xmlns:ns5="http://www.uniquare.com/ubml/db/loandetails/xso/dol/std" is missing..
<conditionList xsi:type="ns5:DbScheduledPaymentXso" id="09xZ3iNcfP3sOT1xzP30" deleted="false" mandatorKey="002 848" optimisticLockAttribute="0" lastChangedAt="2013-06-19T12:57:07.901+02:00" lastChangedById="UBMLTechUser" createdAt="2013-06-19T12:57:07.901+02:00" createdById="UBMLTechUser" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<loanContractId>204A0000050619125703</loanContractId>
<conditionTypeSle>004</conditionTypeSle>
<validFrom>2015-02-28+01:00</validFrom>
<validTo>2015-02-28+01:00</validTo>
<conditionPeriodSle>005</conditionPeriodSle>
<isAnnounced>false</isAnnounced>
<scheduledPaymentTypeSle>002</scheduledPaymentTypeSle>
<percentage>3</percentage>
<amount>100</amount>
<calculationModeSle>002</calculationModeSle>
</conditionList>
Any ideas why this happens??
best regards
Horst