Closed
Description
It's not obvious at first glance how, but https://golang.org/cl/2660 changed the behavior of the XML marshaler for people who were generating xmlns attributes "by hand". For example:
package main
import (
"encoding/xml"
"fmt"
"log"
)
type T struct {
Ns string `xml:"xmlns,attr"`
Body string
}
func main() {
t := &T{Ns: "http://example.com/ns", Body: "hello world"}
x, err := xml.Marshal(t)
if err != nil {
log.Fatal(err)
}
fmt.Printf("%s\n", x)
}
In Go 1.4 this program printed:
<T xmlns="http://example.com/ns"><Body>hello world</Body></T>
After this CL it prints:
<T><Body>hello world</Body></T>
In the absence of compelling justification for a breaking change, I think we should try to continue to support this way of setting the default xmlns.
I've seen tests break due to this change, and presumably real programs would break too, if the xmlns= were important.
What can we do to interpret these old programs correctly in the new more-namespace-aware world for Go 1.5?