-
Notifications
You must be signed in to change notification settings - Fork 17.7k
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 caller to specify preferred namespace prefix #48821
Comments
I think it is really important that the standard library gets proper handling of XML namespaces and namespace prefixes. The current implementation is definitely broken as has been raised in multiple issues. I can elaborate on the problems and short comings if needed, In my view, this PR provides a good solution, or at least a good basis for a solution. I found myself forced to clone the standard xml package together with this patch in my new repo https://github.com/Eyevinn/dash-mpd that handles DASH MPD XMLs and need proper namespaces and prefixes. In the discussion about previous ticket, Dave Cheney argued that one cannot change the behavior of such an established stdlib package as XML due to the risk of breaking someones code. I think there is some truth in that argument, so I'd like to suggest that we start working on a variant of the xml package that supports namespaces and namespace prefixes. It could be called |
I’ve rebased #48641 on top of current master: https://go-review.googlesource.com/c/go/+/355353 |
Hi there, anything I can do to nudge this along? Thanks! |
Would putting this behind |
Hi! Would you mind I raise this issue again? What's the consensus regarding this one? |
The proposed change is spiritually similar to the recent change to allow HTTP verbs in |
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes.
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
Use
xml.Marshal
to marshal namespaced XML, andxml.Unmarshal
to decode that XML.Example: https://play.golang.org/p/-6Ee8tcLl2L
What did you expect to see?
Namespace prefixes preserved round-trip.
What did you see instead?
Namespace prefixes written, but not recognized as the relevant tag when decoding.
Proposal
Change the
encoding/xml
package to allow callers to specify a preferred namespace prefix, and allow decoding of prefixed tags.The preferred prefix can be specified by prefixing the XML tag name in a struct tag or
(xml.Name).Local
.This should be backwards-compatible with existing Go 1
encoding/xml
clients.Example
This change would allow a structure defined above to correctly round-trip encode and decode with namespace prefixes:
Would encode to (and decode from):
Implementation
A working implementation can be found at #48641, built on earlier work by @rogpeppe and others.
Related Issues
This would fix #43168 and update #11431 and #8068.
The text was updated successfully, but these errors were encountered: