Standard library / encoding/xml
encoding/xml.Decoder.Decode()
Reads the next XML element into a destination pointer; use repeatedly for streamed elements. Expected stdout: 'Go\n'.
Formal Syntax & Structure
go syntaxgo
func (d *Decoder) Decode(v any) errorParameters & Attributes
| Name | Type | Description |
|---|---|---|
| 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" "strings")
func must(e error) { if e != nil { panic(e) }}
func main() { d := xml.NewDecoder(strings.NewReader("<a>Go</a>")) var s string must(d.Decode(&s)) fmt.Println(s)}