这是我的 XML 请求正文:
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:ads="http://www.lunalovegood.com/sudarsan/">
<soap:Header/>
<soap:Body>
<ads:Candy>
<ads:toffee>a3f27f3a0a684700e9ab834df492505d806b1944</ads:toffee>
</ads:Candy>
</soap:Body>
</soap:Envelope>
这是我的结构定义:
type CandyMan struct {
SOAPEnvelope
Body struct {
Candy `xml:"Candy"`
} `xml:"Body"`
}
type Candy struct {
Toffee string `xml:"toffee"`
}
type SOAPEnvelope struct {
XMLName xml.Name `xml:"Envelope"`
Text string `xml:",chardata"`
XSI string `xml:"xmlns:xsi,attr"`
XSD string `xml:"xmlns:xsd,attr"`
Soap string `xml:"xmlns:soap,attr"`
}
我正在尝试将 XML 解组到结构中:
req := dtos.CandyMan{}
err := xml.NewDecoder(r.Body).Decode(&req)
fmt.Println(req, err)
我没有收到任何错误,但解组不起作用。我得到一个空结构,请帮我解决问题。谢谢。
繁星coding
相关分类