Thanks for the response, working now! On Monday, November 28, 2016 at 1:47:12 AM UTC-5, Konstantin Khomoutov wrote: > > On Thu, 24 Nov 2016 22:20:44 -0800 (PST) > Chris S <[email protected] <javascript:>> wrote: > > > I am working on trying to parse an xml file with my go code. But I > > keep on getting an error saying: > > > > ./main_v4.go:155: aggInfoXml.IpAddr.Hports undefined (type []Addr has > > no field or method Hports) > [...] > > type AggInfoXml struct { > > Percent IntPercent `xml:"taskprogress,omitempty"` > > IpAddr []Addr `xml:"host>address,omitempty"` > > } > > > > type IntPercent struct { > > Value float64 `xml:"percent,attr,omitempty"` // works > > } > > > > > > type Addr struct { > > Ip string `xml:"addr,attr"` > > Hports []Ports `xml:"host>ports>port,omitempty"` //failing to > > be recognized > > } > [...] > > for _, port := range aggInfoXml.IpAddr.Hports { > > fmt.Printf("Port: %s\n", port.ports()) > > } > > The IpAddr field of the AggInfoXml struct is a slice. > Slices have no fields; but they have elements which should be accessed > through the indexing operation, like in aggInfoXml[0] for instance. > > Hence "aggInfoXml.IpAddr.Hports" has no sense at all. > > You might want to use > > for _, addr := range range aggInfoXml.IpAddr { > for _, port := range addr.Hports { > } > } > > or something like this -- that is, Hports is only defined on instances > of type Addr, not on slices of this type. > > [...] >
-- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/d/optout.
