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

encoding/xml: Marshal fails to handle conflicting tags #18564

Closed
alexd765 opened this issue Jan 8, 2017 · 4 comments
Closed

encoding/xml: Marshal fails to handle conflicting tags #18564

alexd765 opened this issue Jan 8, 2017 · 4 comments
Labels
Documentation FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@alexd765
Copy link
Contributor

alexd765 commented Jan 8, 2017

Please answer these questions before submitting your issue. Thanks!

What version of Go are you using (go version)?

tip and 1.7.4
(this is not a regression)

What operating system and processor architecture are you using (go env)?

linux/amd64

What did you do?

https://play.golang.org/p/w6DV-tXCwT

What did you expect to see?

<A><name2></name2></A>

What did you see instead?

xml: name "name1" in tag of main.A.B conflicts with name "name2" in main.B.XMLName

https://golang.org/pkg/encoding/xml/#Marshal lists the order of preference for the name of an element.

The example works if you remove the tag name1 or name2. This means the order of preferences (name1,name3) and (name2,name3) are working, but (name1,name2) is not.

@titanous
Copy link
Member

titanous commented Jan 9, 2017

This appears to be working as intended. The comment around the code that implements the error says:

If the field type has an XMLName field, the names must match so that the behavior of both marshaling and unmarshaling is straightforward and unambiguous.

Having conflicting name tags in the code is incorrect and this error is designed to point that out.

@alexd765
Copy link
Contributor Author

alexd765 commented Jan 9, 2017

Hm then maybe this is just a documentation issue?

The documentation i linked gave me the impression that there are 5 different ways to name an element and it would be able to handle conflicts by the order of preference.

I would argue that it is a little bit confusing that some conflicts can be handled, but others can't.

@bradfitz bradfitz added this to the Go1.9Maybe milestone Jan 13, 2017
@bradfitz bradfitz added the NeedsFix The path to resolution is known, but the work has not been done. label Jul 20, 2017
@bradfitz bradfitz modified the milestones: Go1.10, Go1.9Maybe Jul 20, 2017
@gopherbot
Copy link

Change https://golang.org/cl/76321 mentions this issue: encoding/xml: add Marshal doc about name conflicts

@leighmcculloch
Copy link
Contributor

I've added a paragraph to the xml.Marshal function docs that mirror the comment in structFieldInfo to bring the knowledge into godocs. CL 76321

@golang golang locked and limited conversation to collaborators Nov 8, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Documentation FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

5 participants