Skip to content
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

proposal: encoding/xml: Allow to omit default namespace declarations #11565

Closed
rsto opened this Issue Jul 3, 2015 · 3 comments

Comments

Projects
None yet
5 participants
@rsto
Copy link
Contributor

rsto commented Jul 3, 2015

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

<foo xmlns="bar"/>

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.

Example

A value of type

type Foo struct {
    XMLName xml.Name `xml:"foons foo"`
    Bar     string   `xml:"barns bar"`
}

encoded with EncodeElement and explicitly declared namespace prefixes "f" for "foons" and "b" for "barns" is currently marshalled as

<foo xmlns="foons" xmlns:b="barns" xmlns:f="foons">
   <bar xmlns="barns"></bar>
</foo>

whereas the following output might be expected

<f:foo xmlns:b="barns" xmlns:f="foons">
  <b:bar></b:bar>
</f:foo>

@ianlancetaylor ianlancetaylor added this to the Unplanned milestone Jul 10, 2015

@mikioh mikioh added the Proposal label Aug 13, 2015

@adg

This comment has been minimized.

Copy link
Contributor

adg commented Sep 25, 2015

ATTN some recent contributors to this package: @rsc @dspezia @rogpeppe @dullgiulio @nigeltao

Does this make sense to you?

@rsto

This comment has been minimized.

Copy link
Contributor Author

rsto commented Sep 25, 2015

This proposal was based on the now reverted XML changes for Go 1.5. I might just as well close this issue and abandon the CL. If there is no other feedback, I'll do so tomorrow.

@adg

This comment has been minimized.

Copy link
Contributor

adg commented Sep 25, 2015

I'll just close it now.

@adg adg closed this Sep 25, 2015

@golang golang locked and limited conversation to collaborators Sep 27, 2016

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
You can’t perform that action at this time.