Golang xml marshal appending items with deeper?



I am going off an example here: http://ift.tt/1MMSpQ5


What if it goes one more deep after Staff?



type Staff struct {
XMLName xml.Name `xml:"staff"`
ID int `xml:"id"`
FirstName string `xml:"firstname"`
LastName string `xml:"lastname"`
UserName string `xml:"username"`
Thing Thing `xml:"thing"`
}


How would I append? I've tried something like this:



v.Staffs = append(v.Staffs, Staff{ID: 108, FirstName: "Jennifer", LastName: "Loh", UserName: "jenniferloh", Thing.tape: "scotch"})


But only making two statements that iterate with the loop worked and its ugly:



v.Staffs = append(v.Staffs, Staff{ID: 108, FirstName: "Jennifer", LastName: "Loh", UserName: "jenniferloh"})

v.Staffs.Thing[i] = append(v.Staffs.Thing, Thing{scotch: "tape"})


Is there a better way to do this? Thanks.


No comments:

Post a Comment