On Tue, Aug 01, 2017 at 10:48:23AM -0700, Marcin Jurczuk wrote: > Your example is returning xml that is wrong from system I'm talking to. > My SOAP service requires tags in few different namespaces. > My code returns: > > * <os:QUERYResponse>* > > Your code returns: > > *<QUERYResponse xmlns="os">* [...] > > > https://play.golang.org/p/hE7vcXbymg [...]
I'm with roger on this: in your example, your sample XML document's text begins with <?xml version="1.0" encoding="UTF-8"?> <os:QUERYResponse> ... which does not define that "os:" bit to denote an XML namespace prefix anywhere. This means the parser does not treat it as such -- it merely considers it to be an integral part of the so-called "local names" of the elements in that XML document. To add to the confusion, you have used those prefixes verbating in the tags of the fields of the types intended to work with the corresponding XML elements. That's why the parser worked: you told it to, say, parse an element literally named "os:QUERYResponse" and so it did that. If you really need to interpret that "os:" bit as an XML namespace prefix, you have to do two things: * Have that prefix defined in your XML document. * Use the full namespace name when you refer to the names of your XML elements - separated by a single space character from their local parts. Hence, say, your XML document should go like <?xml version="1.0" encoding="UTF-8"?> <os:QUERYResponse xmlns:os="http://foo.bar/baz"> ... and you use the full namespace name in your tags like in type QueryResponse struct { XMLName xml.Name `xml:"http://foo.bar/baz QUERYResponse"` -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.