package main import ( "encoding/xml" "fmt" ) type Person struct { Name string `xml:"name"` Age int `xml:"age"` } func main() { xmlData := `` var person Person err := xml.Unmarshal([]byte(xmlData), &person) if err != nil { fmt.Println("Error decoding XML:", err) return } fmt.Printf("Name: %s\n", person.Name) fmt.Printf("Age: %d\n", person.Age) } John 30
Name: John Age: 30Overall, the go encoding.xml Decoder Decode function is a powerful tool for parsing and decoding XML data in Go. It is part of the "encoding/xml" package library, which provides a variety of functions and utilities for working with XML data.