我有一个肥皂请求,我需要做一个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 关注
- 60 浏览
添加回答
举报
0/150
提交
取消