XML
Context
Section titled “Context”The encoding/xml package provides XML marshaling and unmarshaling similar to JSON. Struct tags specify element names and attributes.
Example
Section titled “Example”Marshal a struct to XML.
Code example
Section titled “Code example”package main
import ( "encoding/xml" "fmt")
type Person struct { XMLName xml.Name `xml:"person"` Name string `xml:"name"` Age int `xml:"age"`}
func main() { p := Person{Name: "Alice", Age: 30} data, _ := xml.MarshalIndent(p, "", " ") fmt.Println(string(data))}Output
Section titled “Output”<person> <name>Alice</name> <age>30</age></person>