New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

encoding/xml: loss of xmlns= in encoding since Go 1.4 #11431

Open
rsc opened this Issue Jun 26, 2015 · 6 comments

Comments

Projects
None yet
8 participants
@rsc
Contributor

rsc commented Jun 26, 2015

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?

@rogpeppe @nigeltao

@rsc rsc added this to the Go1.5 milestone Jun 26, 2015

@rogpeppe

This comment has been minimized.

Contributor

rogpeppe commented Jun 29, 2015

Thanks for the report. Proposed https://go-review.googlesource.com/#/c/11635/ as a fix.

@gopherbot

This comment has been minimized.

gopherbot commented Jun 29, 2015

CL https://golang.org/cl/11635 mentions this issue.

@rsc

This comment has been minimized.

Contributor

rsc commented Nov 25, 2015

Blocked on #13400.

@rsc rsc modified the milestones: Go1.7, Go1.6 Nov 25, 2015

@rsc rsc modified the milestones: Go1.8, Go1.7 May 18, 2016

@rsc rsc modified the milestones: Go1.9Early, Go1.8 Oct 26, 2016

@bradfitz bradfitz modified the milestones: Go1.10Early, Go1.9Early May 3, 2017

@bradfitz bradfitz modified the milestones: Go1.10Early, Go1.10 Jun 14, 2017

@rsc rsc modified the milestones: Go1.10, Go1.11 Nov 22, 2017

@iWdGo

This comment has been minimized.

Contributor

iWdGo commented Apr 13, 2018

This is issue is solved by the fix submitted for #20614
I submitted additional tests which provide various solutions to the described problem.

@gopherbot

This comment has been minimized.

gopherbot commented Apr 13, 2018

Change https://golang.org/cl/106835 mentions this issue: encoding/xml : adding tests

@gopherbot

This comment has been minimized.

gopherbot commented Apr 27, 2018

Change https://golang.org/cl/109855 mentions this issue: encoding/xml : Fixes to enforce XML namespace standard

@ianlancetaylor ianlancetaylor removed the Blocked label May 17, 2018

@bradfitz bradfitz modified the milestones: Go1.11, Go1.12 May 18, 2018

@ianlancetaylor ianlancetaylor added this to the Go1.12 milestone Jun 1, 2018

@ianlancetaylor ianlancetaylor modified the milestones: Go1.12, Go1.13 Dec 12, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment