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
+40.5k Golang : Convert to io.ReadSeeker type
+11.2k Golang : How to pipe input data to executing child process?
+7.2k CloudFlare : Another way to get visitor's real IP address
+10.2k Golang : Find and replace data in all files recursively
+19.2k Golang : Delete item from slice based on index/key position
+22.5k Golang : Convert Unix timestamp to UTC timestamp
+5.1k Linux/Unix/MacOSX : Find out which application is listening to port 80 or use which IP version
+8.6k Golang : Convert(cast) []byte to io.Reader type