type Person struct { Name string `xml:"name"` Age int `xml:"age"` } p := Person{Name: "John", Age: 30} xmlBytes, err := xml.Marshal(p) if err != nil { log.Fatal(err) } fmt.Println(string(xmlBytes))
John 30
type Person struct { Name string `xml:"name"` Age int `xml:"age"` } xmlStr := `` p := Person{} err := xml.Unmarshal([]byte(xmlStr), &p) if err != nil { log.Fatal(err) } fmt.Printf("%+v\n", p) John 30
{Name:John Age:30}Overall, this package makes it easy to work with XML in Go by providing a simple way to encode and decode XML.