Groovy XmlSlurper使用命名空间追加节点
我正试图使用Groovy XmlSlurper使用命名空间追加节点,groovy,xmlslurper,Groovy,Xmlslurper,我正试图使用xmlslurper Service.appendNode{ ifx:DepAcctId{ if (acctId!="<!-->"){ifx:AcctId("123")} } } Service.appendNode{ ifx:DepAcctId{ if(acctId!=”{ifx:acctId(“123”)} } } 这导致 <DepAcctId> <AcctId>123</AcctId> </DepAc
xmlslurper
Service.appendNode{
ifx:DepAcctId{
if (acctId!="<!-->"){ifx:AcctId("123")}
}
}
Service.appendNode{
ifx:DepAcctId{
if(acctId!=”{ifx:acctId(“123”)}
}
}
这导致
<DepAcctId>
<AcctId>123</AcctId>
</DepAcctId>
123
我希望它附加名称空间,如
<if:DepAcctId>
<ifx:AcctId>123</ifx:AcctId>
</ifx:DepAcctId>
123
请帮忙
这正是我正在使用的代码
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())
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")
服务=请求'soapenv:Body'。'v2:AcctInqRq'
Service.appendNode{
ifx:DepAcctId{
if(acctId!=“”){ifx:acctId(acctId)}
if(acctType!=“”){ifx:acctType(acctType)}
如果(BankInfo!=”{ifx:BankInfo(BankInfo)}
}
}
xmlBuilder=新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")
屈服请求
}
holderRequest=groovyUtils.getXmlHolder(XmlUtil.serialize(新StreamingMarkupBuilder().bind{mkp.yield request}))
log.info holderRequest.getXml()
tsuite.getTestCaseAt(2).getTestStepByName(tcName).getProperty(“请求”).setValue(holderRequest.getXml())
正在添加标记,但没有ifx
名称空间前缀。您尝试过:
Service.appendNode{
'ifx:DepAcctId'{
if (acctId!="<!-->"){'ifx:AcctId'("123")}
}
}
Service.appendNode{
'ifx:DepAcctId'{
if(acctId!=“ifx:acctId”(“123”)}
}
}
您能为您的问题添加可运行代码和实际异常吗?@RamyaaSeetharaman,这意味着请求。'soapenv:Body.'v2:AcctInqRq'
正在返回null
。。。我的水晶球坏了,所以很难猜出你的xml是什么,看看答案可能是什么……Tim,有没有其他方法可以用名称空间前缀将节点添加到我的xml中?另外,我怀疑请求“soapenv:Body.”“v2:AcctInqRq”是否返回null,因为我的节点正在被添加,只是前缀没有。