Im trying to unmarshal an xml and extract specific nodes out of it, which can be at several different levels. For example, such Xml is valid:
<People>
<Person>
<FullName>Jerome Anthony</FullName>
</Person>
<a>
<Person>
<FullName>Christina</FullName>
</Person>
</a>
</People>
I would like to extract all FullName from this xml, regardless of their nesting level. Example code I tried, which is not working:
type People struct {
Names []string `xml:"FullName"`
}
v := People{Names: []string{}}
err := xml.Unmarshal([]byte(data), &v)
if err != nil {
fmt.Printf("error: %v", err)
return
}
fmt.Printf("Names of people: %q", v)
Remark: This is a simple example for unmarshaling strings, effectively I would like to also unmarshal complex structures.
It seems to me that People has no child named FullName. It has, however, a child named "a" that has a child named FullName.
There's a working example right in the documentation: https://golang.org/pkg/encoding/xml/#example_Unmarshal.