In the following of my snippet, there are two switch statements, one being "switch t := token.(type)", and the second being "switch inElement". I'm wondering why I can't make the second switch statement using the first format, I.e., why I can't use "switch inElement := t.Name.Local" for my second switch statement? It will give "expected switch expression, found simple statement" error BTW.
// Inspect the type of the token just read.
switch t := token.(type) {
case xml.StartElement:
// If we just read a StartElement token
inElement := t.Name.Local
switch inElement {
case "Comment":
{
var c Comment
// decode a whole chunk of following XML into the
// variable c which is a Comment (t above)
decoder.DecodeElement(&c, &t)
fmt.Printf("C: %s\n", c.Comment)
}
case "Included":
{
var r Included
decoder.DecodeElement(&r, &t)
fmt.Printf("I: %s\n", r.Included)
}
}
default:
}