发送soap请求返回的xml
* response.xml
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:ns1="http://dmdelivery.com/webservice/">
<SOAP-ENV:Body>
<ns1:addRecipientResponse>
<addRecipient_result>
<status>DUPLICATE</status>
<statusMsg>Duplicate recipient</statusMsg>
<id>2390018</id>
</addRecipient_result>
</ns1:addRecipientResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
* response.go
package main
import (
"encoding/xml"
"fmt"
"io/ioutil"
"os"
)
type Envelope struct {
XMLName xml.Name `xml:"Envelope"`
Body Body `xml:"Body"`
}
type Body struct {
XMLName xml.Name `xml:"Body"`
AddRecipientResponse AddRecipientResponse `xml:"addRecipientResponse"`
}
type AddRecipientResponse struct {
XMLName xml.Name `xml:addRecipientResponse`
AddRecipientResult AddRecipientResult `xml:addRecipient_result`
}
type AddRecipientResult struct {
XMLName xml.Name `xml:"addRecipient_result"`
Status string `xml:"status"`
StatusMsg string `xml:"statusMsg"`
ID int `xml:"id"`
}
func main() {
file, err := os.Open("response.xml")
if err != nil {
fmt.Println(err.Error())
return
}
defer file.Close()
data, err := ioutil.ReadAll(file)
if err != nil {
fmt.Println(err.Error())
return
}
v := Envelope{}
err = xml.Unmarshal(data, &v)
if err != nil {
fmt.Println(err.Error())
return
}
fmt.Println(v.Body.AddRecipientResponse.AddRecipientResult.Status)
fmt.Println(v.Body.AddRecipientResponse.AddRecipientResult.StatusMsg)
fmt.Println(v.Body.AddRecipientResponse.AddRecipientResult.ID)
}
* test:
$ go run response.go
DUPLICATE
Duplicate recipient
2390018