0
我試圖從波紋管XML的簡單XML的最後一個值,但輸出僅返回名稱的最後一個值Golang XML解組只返回子節點
package main
import (
"encoding/xml"
"fmt"
)
type Member struct {
Name []Names `xml:"names"`
Value string `xml:"value>string"`
}
type Names struct {
Name string `xml:"name"`
}
type Result struct {
Members []Member `xml:"params>param>value>array>data>value>struct>member"`
}
func main() {
data := `
<methodResponse>
<params>
<param>
<value>
<array>
<data>
<value>
<string>12345abcde12345abcde12345</string>
</value>
<value>
<struct>
<member>
<names>
<name> 2 </name>
<name> 3 </name>
<name> 4 </name>
</names>
<value>
<string>trex</string>
</value>
</member>
<member>
<names>
<name> 2 </name>
<name> 3 </name>
<name> 4 </name>
</names>
<value>
<string>trex</string>
</value>
</member>
</struct>
</value>
</data>
</array>
</value>
</param>
</params>
</methodResponse>`
v := Result{}
err := xml.Unmarshal([]byte(data), &v)
if err != nil {
fmt.Printf("error: %v", err)
return
}
fmt.Println(v)
}
嘿,謝謝,這工作像一個魅力和簡單 – Chali