1

を使用してリクエストにノードを追加しようとしていますxmlslurper

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

これにより、

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

のように名前空間を追加したい

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

助けてください。

これは私が使用している正確なコードです。

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

タグが追加されていますが、ifx名前空間のプレフィックスはありません。

4

1 に答える 1

0

やってみました:

Service.appendNode{
  'ifx:DepAcctId'{
    if (acctId!="<!-->"){'ifx:AcctId'("123")}
  }
}
于 2013-04-12T19:52:57.103 に答える