Golang encoding/xml.Encoder.Encoder() function example
package encoding/xml
Encode writes the XML encoding of v to the stream.
See the documentation for Marshal for details about the conversion of Go values to XML.
Encode calls Flush before returning.
Golang encoding/xml.Encoder.Encoder() function usage example
package main
import (
"encoding/xml"
"fmt"
"os"
)
type Address struct {
City, State string
}
type Person struct {
XMLName xml.Name `xml:"person"`
Id int `xml:"id,attr"`
FirstName string `xml:"name>first"`
LastName string `xml:"name>last"`
Age int `xml:"age"`
Height float32 `xml:"height,omitempty"`
Married bool
Address
Comment string `xml:",comment"`
}
func main() {
v := &Person{Id: 13, FirstName: "John", LastName: "Doe", Age: 42}
v.Comment = " Need more details. "
v.Address = Address{"Hanga Roa", "Easter Island"}
encoder := xml.NewEncoder(os.Stdout)
if err := encoder.Encode(v); err != nil { // <-- here
fmt.Println(err)
}
}
Reference :
Advertisement
Something interesting
Tutorials
+14.5k Golang : Overwrite previous output with count down timer
+20.3k Swift : Convert (cast) Int to int32 or Uint32
+5.7k Unix/Linux/MacOSx : Get local IP address
+8.4k Golang : Convert word to its plural form example
+13.9k Golang : How to check if a file is hidden?
+5k Golang : Constant and variable names in native language
+14.7k Golang : Reset buffer example
+4.7k Fix Google Analytics Redundant Hostnames problem
+6.8k Golang : Muxing with Martini example
+11k Golang : Replace a parameter's value inside a configuration file example
+7.8k Golang : Getting Echo framework StartAutoTLS to work
+6.9k Golang : Calculate BMI and risk category