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
+16.5k Golang : Execute terminal command to remote machine example
+5.9k Golang : Generate multiplication table from an integer example
+18.6k Golang : Get download file size
+8.1k Golang : Randomize letters from a string example
+6.8k Golang : Muxing with Martini example
+13.4k Golang : Verify token from Google Authenticator App
+12.3k Golang : How to check if a string starts or ends with certain characters or words?
+6.1k Golang : Create new color from command line parameters
+11.1k Golang : Web routing/multiplex example
+12.5k Golang : "https://" not allowed in import path
+7.3k Golang : Fixing Gorilla mux http.FileServer() 404 problem
+6.1k Golang : How to write backslash in string?