Skip to content

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

Closed
@rsc

Description

@rsc

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeNeedsFixThe path to resolution is known, but the work has not been done.early-in-cycleA change that should be done early in the 3 month dev cycle.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions