Here is fully working/not working/not working example with whole SOAP 
envelope I'm getting from server:
If I use different structs for encoding/decoding it works.

https://play.golang.org/p/hVzB0lh2WH

Change line:
rx := new(SOAPEnvelope2)

to:
rx := new(SOAPEnvelope)

And you will get error that shouldn't exists since serialization suppose to 
be symmetric.



data varibable is copy/paste Encode output from .Encode()

I have exact the same problem like here:
https://github.com/golang/go/issues/9519
When I use different struct for Unmarshaling and Marshalling it works.

But this is a lot of boilerplate code and IMO serialization/deserialization 
to xml for the same struct should give exactly the same outuput :)

Your solution gives different output.



W dniu środa, 2 sierpnia 2017 11:56:09 UTC+2 użytkownik Konstantin 
Khomoutov napisał:
>
> 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.

Reply via email to