1

How does one create a struct in Go for nested xml content? Imagine this xml:

<?xml version="1.0" encoding="UTF-8"?> <people> <person> <name>Pers1</name> <gender>female</gender> <somethings> <thing>123</thing> <thing>321</thing> </somethings> </person> <person> <name>Pers2</name> <gender>male</gender> <somethings> <thing>111</thing> <thing>222</thing> <thing>333</thing> </somethings> </person> <person> <name>Pers3</name> <gender>female</gender> <somethings> <thing>978</thing> </somethings> </person> <!-- And so on... --> </people> 

I'm able to load the data but I can't manage to create a struct for this kind of nested data. Every trick you have would be good to know!

Have a good day! :)

1 Answer 1

3
type Data struct { People []Person `xml:"person"` } type Person struct { Name string `xml:"name"` Gender string `xml:"gender"` Somethings []string `xml:"somethings>thing"` } 

https://play.golang.org/p/q2CKAfiiwQ

Sign up to request clarification or add additional context in comments.

1 Comment

Oh man that's embarrassing, don't know why I could come up with that. Thank you!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.