我有一個soap請求,我需要制作一個xml來進行請求。 所以我所做的xml如下:
我有一個soap請求,我需要制作一個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
", err)
}
// Write the output to check
os.Stdout.Write(output)
這將給我這個輸出 :
<soapenv:Envelope>
<xmlns:soapenvhttp://schemas.xmlsoap.org/soap/envelope/>namespace1</xmlns:soapenv=http://schemas.xmlsoap.org/soap/envelope/>
<soapenv:Body>
<CalculatePrice xmlns="namespace2"/span>> </CalculatePrice>>
</soapenv:Body>>
</soapenv:Envelope>
現在我想在calculateprice里面做一些欄位,我在網上找不到,所以作為例子,xml應該是:
<CalculatePrice xmlns="namespace2">
<test>somevalue</test>
<someothertest>/span>somevalue</someothertest>/span>
</CalculatePrice>/span>
uj5u.com熱心網友回復:
請改變結構命令和XMLEnvelop :-
type Command struct {
Xmlns string `xml: "xmlns,attr"`
測驗 string `xml: "test"`
其他測驗 string `xml: "someothertest"`/span>
}
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: 命令{Xmlns: "namespace2",Test: "somevalue", Someothertest: "somevalue"}}
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/329361.html
標籤:
