I am trying to extract a simple XML from bellow XML, but the output only returns the last value of Name
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)
}