Closed
Description
What version of Go are you using (go version
)?
Go1.21.0
Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (go env
)?
darwin/amd64
What did you do?
There are some incompatible changes in the Go 1.21.0 encoding/xml library. Please take a look at following example:
package main
import (
"encoding/xml"
"fmt"
)
func main() {
type B struct {
XMLName xml.Name `xml:"b"`
C bool `xml:"c"`
}
type A struct {
XMLName xml.Name `xml:"http://example.com a"`
B B
}
var a A
input := `<a xmlns="http://example.com"><b><c>true</c></b></a>`
if err := xml.Unmarshal([]byte(input), &a); err != nil {
fmt.Print(err)
}
output, err := xml.Marshal(&a)
if err != nil {
fmt.Println(err)
}
fmt.Printf("input: %s\r\noutput: %s", input, string(output))
}
What did you expect to see?
Output by Go 1.20.7 and previous Go released version
input: <a xmlns="http://example.com"><b><c>true</c></b></a>
output: <a xmlns="http://example.com"><b><c>true</c></b></a>
What did you see instead?
Output by Go 1.21.0
input: <a xmlns="http://example.com"><b>true</b></a>
output: <a xmlns="http://example.com"><b xmlns=""><c>true</c></b></a>
There are new empty XML namespace xmlns
attributes in the serialized output, which made the input and output XML content inconsistent without any modify.
I created a patch for it and still waiting for a reply, follow up to https://go.dev/cl/466295. Relates to #58401, and external Excelize project issues #1465, #1595 and #1603.
Thanks.