Lots of XML-based formats include an xml:lang attribute on various elements. Reading encoding/xml/typeinfo.go, it looks like this is supposed to work; but I don't see any tests for this functionality, and I can't get it to work in my own code. Here's an example:
package main
import (
"fmt"
"encoding/xml"
)
type foo struct {
XMLName xml.Name `xml:"ns element"`
Attr1 string `xml:"attr1,attr"`
Lang string `xml:"xml lang,attr"`
}
func main() {
f := &foo{XMLName:xml.Name{Space: "ns", Local: "element"}, Attr1: "val1", Lang: "en"}
b, err := xml.Marshal(f)
if err != nil {
fmt.Println(err)
return
}
fmt.Println(string(b))
}
I'm expecting it to print something with xml:lang="en", but it prints lang="en" instead. Is this something I'm doing wrong, or a bug in encoding/xml?
Chris