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
+9k Golang : Go as a script or running go with shebang/hashbang style
+8.3k Golang : Oanda bot with Telegram and RSI example
+7.5k Golang : Process json data with Jason package
+16.8k Golang : Get own process identifier
+6.7k Golang : When to use make or new?
+33.8k Golang : convert(cast) bytes to string
+10.9k Golang : Sieve of Eratosthenes algorithm
+9.3k Golang : Timeout example
+10.2k Golang : Text file editor (accept input from screen and save to file)
+17.9k Golang : Simple client server example
+13.7k Golang : Image to ASCII art example
+6.8k Get Facebook friends working in same company