2017-05-05 112 views
0

我需要构建一个以特定模式发送XML的方法。但我没有找到一种方法来与Grails一起构建。这是我需要构建的XML示例。谁能帮我?用Grails创建XML请求的SOAP请求

<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> 
+0

我不相信你没有发现像http://mrhaki.blogspot.de/2009/10/groovy-goodness-creating-xml任何信息-with.html到目前为止... – injecteer

+0

我已经看过这个链接。我必须测试,但不能重现类似的输出。如果你有一个更大的域,请给我看一个我需要的输出示例的类似示例。谢谢 –

回答

0

喜欢的东西:

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)