I'm trying to unmarshal some XML, where I want to parse the attributes in a special way. I have tried using the UnmarshalerAttr interface but I cannot get it working. Using the following code, the only output I get is '{Castle}'
package main
import (
"encoding/xml"
"fmt"
"strings"
)
type Show struct {
Title string `xml:"Title,attr"`
}
func (s *Show) UnmarshalXMLAttr(attr xml.Attr) error {
fmt.Printf("Parsing attribute '%s', with value '%s'", attr.Name.Local, attr.Value)
s.Title = strings.ToUpper(attr.Value)
return nil
}
func main() {
b := []byte(`<Series Title="Castle"></Series>`)
var show Show
xml.Unmarshal(b, &show)
fmt.Println(show)
}
Any ideas?