Golang encoding/xml.Decoder.Decode() function example
package encoding/xml
Decode works like xml.Unmarshal, except it reads the decoder stream to find the start element.
Golang encoding/xml.Decoder.Decode() function usage example
type xmlRegistry struct {
Types []xmlType `xml:"types>type"`
Enums []xmlEnumSet `xml:"enums"`
Commands []xmlCommand `xml:"commands>command"`
Features []xmlFeature `xml:"feature"`
Extensions []xmlExtension `xml:"extensions>extension"`
}
func readSpecFile(file string) (*xmlRegistry, error) {
var registry xmlRegistry
f, err := os.Open(file)
if err != nil {
return nil, err
}
defer f.Close()
err = xml.NewDecoder(f).Decode(®istry) // <----- here
if err != nil {
return nil, err
}
return ®istry, nil
}
Reference :
Advertisement
Something interesting
Tutorials
+6.1k Golang : Debug with Godebug
+9.1k Golang : Intercept and compare HTTP response code example
+4.9k Javascript : How to get width and height of a div?
+21.7k Golang : Setting up/configure AWS credentials with official aws-sdk-go
+21.1k Golang : Sort and reverse sort a slice of strings
+18.6k Golang : Get download file size
+7.5k Golang : Handling Yes No Quit query input
+8k Golang : Handle Palindrome string with case sensitivity and unicode
+11.6k Android Studio : Create custom icons for your application example
+9.7k Golang : Eroding and dilating image with OpenCV example
+6.1k PageSpeed : Clear or flush cache on web server
+13.9k Golang : How to determine if a year is leap year?