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
+5.2k Responsive Google Adsense
+9.7k Golang : Find correlation coefficient example
+21.6k Golang : GORM create record or insert new record into database example
+6.9k Golang : How to solve "too many .rsrc sections" error?
+6.6k Golang : Totalize or add-up an array or slice example
+15.2k JavaScript/JQuery : Detect or intercept enter key pressed example
+13.6k Golang : Qt progress dialog example
+5.6k Golang : Detect words using using consecutive letters in a given string
+11.3k Golang : How to pipe input data to executing child process?
+13k Swift : Convert (cast) Int to String ?
+9.4k Golang : Scramble and unscramble text message by randomly replacing words
+6.1k Golang : Dealing with backquote