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
+26.4k Golang : Get executable name behind process ID example
+5.4k Golang : What is StructTag and how to get StructTag's value?
+11.3k Golang : Post data with url.Values{}
+19.6k Golang : Close channel after ticker stopped example
+4.6k JavaScript : Rounding number to decimal formats to display currency
+7k Web : How to see your website from different countries?
+6.9k Golang : Calculate BMI and risk category
+16.3k Golang :Trim white spaces from a string
+19.4k Golang : Fix cannot download, $GOPATH not set error
+13.9k Golang : convert(cast) string to float value
+10.6k Golang : Get local time and equivalent time in different time zone
+22.4k Golang : Read directory content with filepath.Walk()