Standard library / encoding/xml
encoding/xml.Decoder.Token()
Returns the next validated XML token, resolving namespace prefixes. Copy retained byte-backed tokens before the next read. Expected stdout: 'urn:x\n'.
Formal Syntax & Structure
go syntaxgo
func (d *Decoder) Token() (Token, error)Return Value
(Token, error)
Token and error, including io.EOF at end of input.
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(`<p:a xmlns:p="urn:x"/>`)) t, e := d.Token() must(e) fmt.Println(t.(xml.StartElement).Name.Space)}