我是新手,对于Golang和Soap不熟悉,并且在解析soap消息时遇到了麻烦。
1.我有一个Soap消息
<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/">
<soap:Body>
<activationPack_completeResponse"http://tempuri.org/">
<activationPack_completeResult xsi:type="xsd:string">Active</activationPack_completeResult>
</activationPack_completeResponse>
</soap:Body>
</soap:Envelope>
现在该如何在Golang中对它们进行反序列化,我的结构体声明应该包含标记"SOAP Envelope"?
我有以下一些结构:
type MyRespEnvelope struct {
XMLName xml.Name `xml:"http://schemas.xmlsoap.org/soap/envelope/ Envelope"`
Soap *Body
}
type Body struct {
XMLName xml.Name `xml:"http://schemas.xmlsoap.org/soap/envelope/ Body"`
GetResponse *ActivationPack_CompleteResponse
}
type ActivationPack_CompleteResponse struct {
XMLName xml.Name `xml:"activationPack_completeResponse"`
Id string `xml:"xmlns,attr"`
MyVar string `xml:"activationPack_completeResult"`
}
但是我遇到了以下错误:
error: expected element <Envelope> in name space http://schemas.xmlsoap.org/soap/envelope/ but have soap*stopped,reason="end-stepping-range",frame={addr="0x0000000000401211",func="main.UnmarshalFirstDitto",args=[{name="data",value="\"\\nNotice: Undefined variable: area in /var/www/nusoap/dittotv.php on line 25\\n\\nNotice: Undefined variable: area in /var/www/nusoap/dittotv.php on line 27\\n\\nNotice: Undefined variable: area in /var/www/nu\"..."}],file="/media/winshare/Golang/WorkSpace/src/DittoTv/ditto.go",fullname="/media/winshare/Golang/WorkSpace/src/DittoTv/ditto.go",line="60"},thread-id="1",stopped-threads="all",core="0"
请问如何声明结构体以便于解析SOAP消息?
args=[{name="data",value="\"\\n注意:/ var / www / nusoap / dittotv.php第25行中未定义变量:area \\n...
- James Henstridge<SOAP-ENV:Envelope>
,则需要使用xmlns:SOAP-ENV
属性。也许可以尝试将文档提供给xmllint
工具以验证其是否有效。 - James Henstridgexmllint
运行该文档,以查看其是否真实有效? - James Henstridge