Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upencoding/xml: namespaced and non-namespaced attributes conflict #11724
Comments
ianlancetaylor
added this to the Unplanned milestone
Jul 15, 2015
This comment has been minimized.
This comment has been minimized.
This is unfortunate. The existing Go convention is that if no namespace is specified Changing that will break existing code. One possibility might be to make the tag
might be possible, though ugly. |
This comment has been minimized.
This comment has been minimized.
Is this documented anywhere? I might've missed that, but the package docs don't seem to mention that. Might be a documentation issue. Also, why can't that be changed to "if no namespace is specified in the struct tag, it will match any namespace including the empty namespace but excluding fields with the same name that explicitly specify their namespace" (or something better worded)? This doesn't seem like it would break anyone's code, because right now having |
This comment has been minimized.
This comment has been minimized.
Yes - this could definitely do with better docs - please feel free to raise an issue.
I'm not sure that would work very well. If I'm trying to unmarshal from an attribute This is a particular problem because attributes are in the empty namespace by |
ainar-g
referenced this issue
Jul 16, 2015
Open
encoding/xml: empty namespace conventions are badly documented #11735
This comment has been minimized.
This comment has been minimized.
Raised #11735. If the convention won't be changed (at least, not until Go 2.0), then we could use the form Still, when there's a change to change the convention (e.g. 2.0), I'd suggest to make |
This comment has been minimized.
This comment has been minimized.
mmcdole
commented
Oct 9, 2015
@rogpeppe just ran into this issue myself trying to unmarshal RSS documents which use the "itunes" namespace. My documents will sometimes have Until Go's behavior is changed, what can we do to work around this? |
This comment has been minimized.
This comment has been minimized.
@mmcdole Such questions are better off on StackOverflow, golang-nuts, or other forums. Also more people would be able to help you if you provide an MCVE. The workaround I originally proposed at golang-ru is to replace all namespaced attributes in test with a modified one, i.e. replace |
This comment has been minimized.
This comment has been minimized.
pdw-mb
commented
Feb 17, 2016
This looks like a duplicate of #8535 . |
This comment has been minimized.
This comment has been minimized.
gopherbot
commented
Apr 12, 2018
Change https://golang.org/cl/106575 mentions this issue: |
This comment has been minimized.
This comment has been minimized.
In the first example, the namespace is not bound. This is mandatory (https://www.w3.org/TR/xml-names/#dt-NSName). If fixed, this issue is a duplicated of #8535 and the same fix submitted applies. |
ainar-g commentedJul 15, 2015
Go versions:
Code: http://play.golang.org/p/S2LU2vfk4i.
Expected: no error and
main.Discount{XSIType:"ProgressivePromotion", Type:"Percent", From:"2015-07-28T00:00:00", To:"2015-07-30T00:00:00"}
Got:
error: main.Discount field "XSIType" with tag "xsi type,attr" conflicts with field "Type" with tag "type,attr"
Found by Eugene Toropov at golang-ru. May be related to #3703.