Trying to parse xml containing an array using encoding/xml package
import ( "fmt" "encoding/xml" ) var data = ` <Patient> <Name> <LastName>Biscayne</LastName> <FirstName>Sophia</FirstName> </Name> <Gender>F</Gender> <CommunicationNumbers> <Communication> <Number>9415551223</Number> <Qualifier>TE</Qualifier> </Communication> <Communication> <Number>4055559999</Number> <Qualifier>TE</Qualifier> </Communication> </CommunicationNumbers> </Patient> ` type Name struct { LastName string FirstName string } type Communication struct { Number string `xml:Number` Qualifier string `xml:Qualifier` } type Patient struct { Name Name Gender string CommunicationNumbers []Communication `xml:CommunicationNumbers>Communication` } func main() { patient := Patient{} _ = xml.Unmarshal([]byte(data), &patient) fmt.Printf("%#v\n", patient) } I am not able to get communication numbers. The output is as follows:
main.Patient{Name:main.Name{LastName:"Biscayne", FirstName:"Sophia"}, Gender:"F", CommunicationNumbers:[]main.Communication{main.Communication{Number:"", Qualifier:""}}}