Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
encoding/xml: support QName values / expose namespace bindings #12406
It's not uncommon for XML to contain QNames as element and attribute values, e.g.
In order to correctly unmarshal the value, you need to know the namespace bindings in effect for my-element, but Decoder doesn't appear to expose this information. A simple addition to encoding/xml of:
allows unmarshallers to access the necessary information, for example, I can now write:
Arguably, something like the above, and a corresponding attribute unmarshaller could be provided on the standard xml.Name.
More discussion of this issue here:
go version go1.5 darwin/amd64
This could help with an issue I reported at hooklift/gowsdl#37
In that case, the
Having access to the namespaces from the outer
referenced this issue
Sep 11, 2015
Thanks @rsc. I think what's there is pretty close. QName values in XML documents are inherently problematic because you need access to the current namespace bindings in order to understand them, but they are fairly widely used.
After filing this issue, I've realised that the fix for attributes is more problematic as UnmarshallXMLAttr doesn't currently get passed the Decoder object, so addressing this would require a breaking change to the API, rather than just the addition of a method.
changed the title from
encoding/xml: Support QName values / expose namespace bindings
encoding/xml: support QName values / expose namespace bindings
Nov 5, 2015
I've implemented the proposed change in a fork that can be found here: https://code.blinkace.com/go/xml
The relevant changes are:
I've also implemented a QName package which is a Marshaler / Unmarshaler. This might be better merged with XMLName.