From the encoding/xml Unmarshal documentation:
- If the XMLName field has an associated tag of the form
“name” or “namespace-URL name”, the XML element must have
the given name (and, optionally, name space) or else Unmarshal
returns an error.
thx
why RspEnvelope.XMLName tag is xml:"Envelope"
not xml:"soap:Envelope"
Perhaps it should be! I took the example you posted and replaced the “short” XML namespace declarations with their full definitions. RspEnvelope.XMLName
didn’t have a namespace, so when I did a replace, I didn’t catch it.
// RspEnvelope is a SOAP envelope.
type RspEnvelope struct {
XMLName xml.Name `xml:"Envelope"`
If it should be in a namespace, I suggest putting it in one similarly to how I replaced the other namespaces.
Often on this forum, I’m just trying to serve as “another set of eyes” in an attempt to help both the one asking the question and myself become better programmers!
You can’t put the short XML names in the struct tags like
`xml:"soap:Header"`
You have to put the full namespace URL:
`xml:"http://schemas.xmlsoap.org/soap/envelope/ Header"`
Looks like the namespaces might only matter if there’s ambiguity. You probably only need the namespaces if you’re doing something like this: https://play.golang.org/p/0T9sy6Lv7UA
thx
This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.