Standard library / encoding/xml
encoding/xml.UnmarshalerAttr
Custom attribute decoding interface; receives the full Attr and can validate the value. Expected stdout: 'Go\n'.
Formal Syntax & Structure
go syntaxgo
type UnmarshalerAttr interface { UnmarshalXMLAttr(attr Attr) error}Working Example
Example Snippetgo
package main
import ( "encoding/xml" "fmt")
func must(e error) { if e != nil { panic(e) }}
type label string
func (v *label) UnmarshalXMLAttr(a xml.Attr) error { *v = label(a.Value); return nil }func main() { var v label var u xml.UnmarshalerAttr = &v must(u.UnmarshalXMLAttr(xml.Attr{Value: "Go"})) fmt.Println(v)}