我有一個肥皂請求,我需要做一個xml來提出請求。所以我做了什么來制作xml如下:type Command struct { XMLName xml.Name } type XMLEnvelop struct { XMLName xml.Name `xml:"soapenv:Envelope"` Xmlns string `xml:"xmlns:soapenv=http://schemas.xmlsoap.org/soap/envelope/,"` CalculatePrice Command `xml:"soapenv:Body>FunctionName"` } v := &XMLEnvelop{Xmlns: "namespace1", CalculatePrice: Command{xml.Name{"namespace2", "CalculatePrice"}}} output, err := xml.MarshalIndent(v, "", " ") if err != nil { fmt.Printf("error: %v\n", err) } // Write the output to check os.Stdout.Write(output)這將給我這個輸出:<soapenv:Envelope> <xmlns:soapenv=http://schemas.xmlsoap.org/soap/envelope/>namespace1</xmlns:soapenv=http://schemas.xmlsoap.org/soap/envelope/> <soapenv:Body> <CalculatePrice xmlns="namespace2"></CalculatePrice> </soapenv:Body></soapenv:Envelope>現在我想在網絡上找不到它的一些字段,所以作為例子,xml會是這樣的:calculateprice <CalculatePrice xmlns="namespace2"> <test>somevalue</test> <someothertest>somevalue</someothertest> </CalculatePrice>
1 回答

Helenr
TA貢獻1780條經驗 獲得超4個贊
請更改結構命令和 XML 擴展 :-
type Command struct {
Xmlns string `xml:"xmlns,attr"`
Test string `xml:"test"`
Someothertest string `xml:"someothertest"`
}
type XMLEnvelop struct {
XMLName xml.Name `xml:"soapenv:Envelope"`
Xmlns string `xml:"xmlns:soapenv=http://schemas.xmlsoap.org/soap/envelope/,"`
CalculatePrice Command `xml:"soapenv:Body>CalculatePrice"`
}
并更改v := &XMLEnvelop{Xmlns: "namespace1", CalculatePrice: Command{Xmlns: "namespace2",Test: "somevalue", Someothertest: "somevalue"}}
- 1 回答
- 0 關注
- 70 瀏覽
添加回答
舉報
0/150
提交
取消