dqy0707 2015-10-05 10:57
浏览 56

在GOLANG中使用带有名称空间的SOAP

i'm a GO newbie, starting to learn how to process SOAP requests. I have a difficulty here with the namespaces: i don't know how to contruct the structs to reflect such kind of data coming in from the webservice in order to unmarshall it. Could you give me a few hints here? I'm using GO 1.5.1

<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="https://webapi.allegro.pl/service.php">
<SOAP-ENV:Body>
    <ns1:doQueryAllSysStatusResponse>
        <ns1:sysCountryStatus>

            <ns1:item>
                <ns1:countryId>1</ns1:countryId>
                <ns1:programVersion>1.0</ns1:programVersion>
                <ns1:catsVersion>1.1.87</ns1:catsVersion>
                <ns1:apiVersion>1.0</ns1:apiVersion>
                <ns1:attribVersion>1.0</ns1:attribVersion>
                <ns1:formSellVersion>1.4.46</ns1:formSellVersion>
                <ns1:siteVersion>1.0</ns1:siteVersion>
                <ns1:verKey>123131231</ns1:verKey>
            </ns1:item>

            <ns1:item>
                <ns1:countryId>56</ns1:countryId>
                <ns1:programVersion>1.0</ns1:programVersion>   
                <ns1:catsVersion>1.0.43</ns1:catsVersion>
                <ns1:apiVersion>1.0</ns1:apiVersion> 
                <ns1:attribVersion>1.0</ns1:attribVersion>
                <ns1:formSellVersion>1.0.69</ns1:formSellVersion>
                <ns1:siteVersion>1.0</ns1:siteVersion>
                <ns1:verKey>00000101</ns1:verKey>
            </ns1:item>
        </ns1:sysCountryStatus>
    </ns1:doQueryAllSysStatusResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
  • 写回答

1条回答 默认 最新

  • dotelauv682684 2015-10-05 13:41
    关注

    You can a structure that matches your SOAP data and then unmarshal it with the "encoding/xml" package

    Structs :

    type Envelope struct {
        XMLName  xml.Name `xml:"SOAP-ENV:Envelope"`
        Body     Body     `xml:"SOAP-ENV:Body"`
    }
    
    type Body struct {
        StatusRes *DoQueryAllSysStatusResponse `xml:"ns1:doQueryAllSysStatusResponse"`
    }
    
    type DoQueryAllSysStatusResponse struct {
        CountryStatus *SysCountryStatus `xml:"ns1:sysCountryStatus"`
    }
    
    // ...
    

    Unmarshal:

    data := []byte{} // SOAP data
    env := &Envelope{}
    err := xml.Unmarshal(data, env)
    if err != nil {
        // do something
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度