Forum Discussion

sahanarangain's avatar
sahanarangain
New Contributor
13 years ago

Problem Appending XML nodes in SOAP Ui using Groovy

Hi All,

I am trying to append node to my request using xmlslurper

Service.appendNode{
ifx:DepAcctId{
if (acctId!="<!-->"){ifx:AcctId("123")}
}
}


This results in

<DepAcctId>
<AcctId>123</AcctId>
</DepAcctId>


But I want as:


<if:DepAcctId>
<ifx:AcctId>123</ifx:AcctId>
</ifx:DepAcctId>

where in the namespaces are not getting added.

The exact code that I am using is as follows:


holderRequest = tsuite.getTestCaseAt(2).getTestStepByName(tcName).testRequest.getRequestContent()
request = new XmlSlurper(true,true).parseText(holderRequest).declareNamespace(v2:'http://www.fnf.com/xes/services/acct/acctinq/v2_1',
ifx:"http://www.ifxforum.org/IFX_150",soapenv:"http://schemas.xmlsoap.org/soap/envelope/", xes:"http://www.fnf.com/xes")
Service = request.'soapenv:Body'.'v2:AcctInqRq'
Service.appendNode{
ifx:DepAcctId{
if (acctId!="<!-->"){ifx:AcctId(acctId)}
if (acctType!="<!-->"){ifx:AcctType(acctType)}
if (BankInfo!="<!-->"){ifx:BankInfo(BankInfo)}
}
}
xmlBuilder = new StreamingMarkupBuilder()
writer = xmlBuilder.bind {
mkp.declareNamespace(soapenv:"http://schemas.xmlsoap.org/soap/envelope/",ifx:"http://www.ifxforum.org/IFX_150",
v2:"http://www.fnf.com/xes/services/acct/acctinq/v2_1",xes:"http://www.fnf.com/xes")
mkp.yield request
}
holderRequest = groovyUtils.getXmlHolder(XmlUtil.serialize(new StreamingMarkupBuilder().bind {mkp.yield request}))
log.info holderRequest.getXml()
tsuite.getTestCaseAt(2).getTestStepByName(tcName).getProperty("request").setValue(holderRequest.getXml())



This is quite urgent. Please let me know asap.


Thanks
Sahana

1 Reply

  • nmrao's avatar
    nmrao
    Community Hero
    Hi,

    Understand that namespace is missing after update is done.

    You may try the following though not sure/tested.

    from:
    request = new XmlSlurper(true,true).parseText(holderRequest).declareNamespace(v2:'http://www.fnf.com/xes/services/acct/acctinq/v2_1',
    ifx:"http://www.ifxforum.org/IFX_150",soapenv:"http://schemas.xmlsoap.org/soap/envelope/", xes:"http://www.fnf.com/xes")


    to:
    request = new XmlSlurper(true,true).parseText(holderRequest).declareNamespace([v2:'http://www.fnf.com/xes/services/acct/acctinq/v2_1',
    ifx:"http://www.ifxforum.org/IFX_150",soapenv:"http://schemas.xmlsoap.org/soap/envelope/", xes:"http://www.fnf.com/xes"])


    Note that namespaces K,V are included inside [, ]

    Regards,
    Rao.