Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.Sign up
proposal: encoding/xml: Allow to omit default namespace declarations #11565
Problem and Proposal
Currently, an arbitrary Go value marshalled to XML with a (non-local) XML namespace sets the default namespace for its start element and all elements contained within it. For example, a value with local name "foo" in the "bar" namespace would be marshalled as
While this leads to succinct XML most of the times, it does not work well with the newly added 1.5 feature to declare custom namespace prefixes: the xml.Encoder marshals the xml prefix declarations but ignores them while marshalling inner XML elements (see the example below).
I propose to make the declaration of default namespaces optional, and activated by default for backward-compatibility. To do so, I outlined a proof of concept in CL 11074.
A value of type
encoded with EncodeElement and explicitly declared namespace prefixes "f" for "foons" and "b" for "barns" is currently marshalled as
whereas the following output might be expected