你好,我是golang和編程的新手,我有一個(gè)新手問題。我無法在谷歌上找到答案。soap 服務(wù)器因 gowsdl 生成的代碼而失敗。但是我添加這個(gè)xmlns=“”來驗(yàn)證標(biāo)簽,它的工作原理就像一個(gè)魅力。那么我怎么能不通過字符串替換而是習(xí)慣性的方式將其添加到標(biāo)簽中呢?服務(wù)器不接受<Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/"><Body xmlns="http://schemas.xmlsoap.org/soap/envelope/"> <GetCitiesRequest xmlns="http://www.n11.com/ws/schemas"> <auth> <<<<<<<<<<<<<<<<------------ fails because no xmlns="" <appKey>xxx</appKey> <appSecret>xx</appSecret> </auth> </GetCitiesRequest> </Body></Envelope>服務(wù)器接受 <Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/"> <Body> <GetCitiesRequest xmlns="http://www.n11.com/ws/schemas"> <auth xmlns=""> <appKey>[string]</appKey> <appSecret>[string]</appSecret> </auth> </GetCitiesRequest> </Body></Envelope>im使用快速修復(fù):buffers := new(bytes.Buffer)buffers.WriteString(strings.ReplaceAll(buffer.String(),"<auth>","<auth xmlns=\"\">"))req, err := http.NewRequest("POST", s.url, buffers)我應(yīng)該添加什么結(jié)構(gòu)標(biāo)簽來查看空的xmlns=“” ?type GetCitiesRequest struct { XMLName xml.Name `xml:"http://www.n11.com/ws/schemas GetCitiesRequest"` Auth *Authentication `xml:"auth,omitempty" json:"auth,omitempty"`}type Authentication struct { AppKey string `xml:"appKey,omitempty" json:"appKey,omitempty"` AppSecret string `xml:"appSecret,omitempty" json:"appSecret,omitempty"`}阿洛斯我試過了;type Authentication struct { XMLName xml.Name `xml:""` AppKey string `xml:"appKey,omitempty" json:"appKey,omitempty"` AppSecret string `xml:"appSecret,omitempty" json:"appSecret,omitempty"`} auth := Authentication{AppKey:"secret",AppSecret:"secret"} auth.XMLName.Local= "auth" auth.XMLName.Space = ""我也嘗試 auth.XMLName.Space = “ ” 空白空間,但xml.marshal將其轉(zhuǎn)換為轉(zhuǎn)義字符,如“"e,#34”我想了解我如何做到像專業(yè)的方式,但不是菜鳥的方式。任何幫助贊賞。謝謝。
1 回答

繁花不似錦
TA貢獻(xiàn)1851條經(jīng)驗(yàn) 獲得超4個(gè)贊
https://golang.org/pkg/encoding/xml/#Marshal
帶有標(biāo)記“name,attr”的字段將成為 XML 元素中具有給定名稱的屬性。
帶有標(biāo)記 “,attr” 的字段將成為 XML 元素中具有字段名稱的屬性。
type Authentication struct { Xmlns string `xml:"xmlns,attr" json:"-"` AppKey string `xml:"appKey,omitempty" json:"appKey,omitempty"` AppSecret string `xml:"appSecret,omitempty" json:"appSecret,omitempty"`}
https://play.golang.org/p/iIvlUoaYvgB
- 1 回答
- 0 關(guān)注
- 95 瀏覽
添加回答
舉報(bào)
0/150
提交
取消