Standard library / encoding/xml
encoding/xml.Unmarshal()
Decodes XML into a pointer using tags and exported fields. Unmatched well-formed content can be discarded. Expected stdout: 'Ada\n'.
Formal Syntax & Structure
go syntaxgo
func Unmarshal(data []byte, v any) errorParameters & Attributes
| Name | Type | Description |
|---|---|---|
| data | []byte | Input bytes for XML, or fixed-size value / destination pointer for binary operations. |
| v | any | Value to encode or pointer to the destination for decoding. |
Return Value
error
Nil on success; otherwise the operation error.
Working Example
Example Snippetgo
package main
import ( "encoding/xml" "fmt")
func must(e error) { if e != nil { panic(e) }}
func main() { var v struct { Name string `xml:"name"` } must(xml.Unmarshal([]byte("<user><name>Ada</name></user>"), &v)) fmt.Println(v.Name)}