1

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>

I want it to append the namespace, like

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

Please help.

This is the exact code that I am using.

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())

The tags are getting added but without the ifx namespace prefix.

Gergely Toth
  • 6,638
  • 2
  • 38
  • 40

1 Answers1

0

Have you tried:

Service.appendNode{
  'ifx:DepAcctId'{
    if (acctId!="<!-->"){'ifx:AcctId'("123")}
  }
}
tim_yates
  • 167,322
  • 27
  • 342
  • 338
  • Can you add runnable code and the actual exception to your question? – tim_yates Apr 15 '13 at 16:46
  • @RamyaaSeetharaman so that means `request.'soapenv:Body'.'v2:AcctInqRq'` is returning `null`... My crystal ball is broken, so it's hard to guess what your xml is to see what the answer might be... – tim_yates Apr 16 '13 at 13:07
  • Tim, is there any other way that I could add nodes to my xml with namespace prefix? Also I'm doubtful that request.'soapenv:Body'.'v2:AcctInqRq' is returning null because my nodes are getting added,just the prefix is not. – Ramyaa Seetharaman Apr 16 '13 at 13:21