Standard library / encoding/xml

encoding/xml.NewTokenDecoder()

Wraps a TokenReader with a decoder that consumes tokens rather than raw XML bytes. Expected stdout: 'Go\n'.

Formal Syntax & Structure

go syntaxgo
func NewTokenDecoder(t TokenReader) *Decoder

Parameters & Attributes

NameTypeDescription
tTokenReaderXML token or token reader, according to the signature.

Return Value

*Decoder

New XML decoder.

Working Example

Example Snippetgo
package main
import (  "encoding/xml"  "fmt"  "strings")
func must(e error) {  if e != nil {    panic(e)  }}
func main() {  d := xml.NewTokenDecoder(xml.NewDecoder(strings.NewReader("<a>Go</a>")))  var s string  must(d.Decode(&s))  fmt.Println(s)}
Go Reference