xml - 使用Grails使用XML创建SOAP请求

标签 xml grails soap

我需要构造一个以某种模式发送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/

相关文章:

java - 如何在 Java 中创建具有多个模式的 XML 文档?

xml - 使用 XSLT 复制 XML 中的所有节点,支持特殊情况

spring - 端点 SWS 没有适配器

soap - 如何通过 Web 服务发送 ArrayList?

scala中的xml属性解析

grails - 为Apache Camel 设置跟踪

templates - Grails和gsp : How to render nested template with the same model/bean?

grails - Grails是否具有类似于django-debug-toolbar(djdt)的插件?

node.js - 如何使用soap和nodejs向chronopost发出运输请求

javascript - 你如何用jquery找出根元素是什么元素类型