XML
Contexte
Section intitulée « Contexte »Le package encoding/xml fournit le marshaling et unmarshaling XML similaire au JSON. Les tags de structure spécifient les noms d’éléments et les attributs.
Marshaller une structure en XML.
Code exemple
Section intitulée « Code exemple »package main
import ( "encoding/xml" "fmt")
type Personne struct { XMLName xml.Name `xml:"personne"` Nom string `xml:"nom"` Age int `xml:"age"`}
func main() { p := Personne{Nom: "Alice", Age: 30} donnees, _ := xml.MarshalIndent(p, "", " ") fmt.Println(string(donnees))}<personne> <nom>Alice</nom> <age>30</age></personne>