我需要构造一个以某种模式发送XML的方法。但是我找不到用Grails构建它的方法。这是我需要构建的XML示例。谁能帮我?
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:sic="http://www.example.com/">
<soapenv:Header/>
<soapenv:Body>
<sic:IncPrePrTyped>
<sic:clsProp>
<sic:datDataSist>2017-02-02</sic:datDataSis>
<sic:datDataVali>2017-02-02</sic:datDataVali>
<sic:strEmpr>01</sic:strEmp>
<sic:strProd>0071</sic:strProd>
<sic:strBand02</sic:strBand>
<sic:strFil>0001</sic:strFil>
<sic:strPontAtend>3424</sic:strPontAtend>
<sic:strAtend>A5F1</sic:strAtend>
<sic:datDataProp>2017-02-01</sic:datDataProp>
<sic:strClient>24517666034</sic:strClient>
<sic:strName>BENTO DA SILVA AMARAL</sic:strName>
<sic:strDataNasc>27/06/1952</sic:strDataNasc>
</sic:clsProp>
</sic:IncPrePropTyped>
</soapenv:Body>
</soapenv:Envelope>
最佳答案
就像是:
import groovy.xml.StreamingMarkupBuilder
import groovy.xml.XmlUtil
def xmlBuilder = new StreamingMarkupBuilder()
writer = xmlBuilder.bind {
mkp.declareNamespace( 'soapenv': "http://schemas.xmlsoap.org/soap/envelope/" )
mkp.declareNamespace( 'sic': "http://www.example.com/" )
'soapenv:Envelope' {
'soapenv:Header'()
'soapenv:Body' {
'sic:IncPrePrTyped' {
'sic:clsProp' {
'sic:datDataSist'('2017-02-02')
'sic:datDataVali'('2017-02-02')
'sic:strEmpr'('01')
'sic:strProd'('0071')
'sic:strBand'('02')
'sic:strFil'('0001')
'sic:strPontAtend'('3424')
'sic:strAtend'('A5F1')
'sic:datDataProp'('2017-02-01')
'sic:strClient'('24517666034')
'sic:strName'('BENTO DA SILVA AMARAL')
'sic:strDataNasc'('27/06/1952')
}
}
}
}
}
println XmlUtil.serialize( writer )
关于xml - 使用Grails使用XML创建SOAP请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43806960/