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

Comments

Projects
None yet
5 participants
@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

This comment has been minimized.

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

This comment has been minimized.

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 label Jul 20, 2017

@bradfitz bradfitz modified the milestones: Go1.10, Go1.9Maybe Jul 20, 2017

@gopherbot

This comment has been minimized.

Copy link

gopherbot commented Nov 7, 2017

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

@leighmcculloch

This comment has been minimized.

Copy link
Contributor

leighmcculloch commented Nov 7, 2017

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

@gopherbot gopherbot closed this in 65a864a Nov 8, 2017

@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.
You can’t perform that action at this time.