Soap XML Unmarshal TagName(s) which contain Colons

1,479 views
Skip to first unread message

YardVox

unread,
Mar 20, 2013, 4:44:42 PM3/20/13
to golan...@googlegroups.com
Facing a requirement to deal with Soap and xml tag names containing Colons.

(see linked program below ) Go pkg Unmarshal errors when
the syntax  `xml:"soap:Envelope"` is seen.

Is there alternate syntax/workaround to get Unmarshal process xml tag names containing colons

type Envelope struct {
        XMLName  xml.Name `xml:"soap:Envelope"`
//      XMLName  xml.Name `xml:"soapEnvelope"`
        Soap     *SoapBody
}


http://play.golang.org/p/fgrFhlAcYs

Dmytro

unread,
Mar 20, 2013, 5:03:51 PM3/20/13
to golan...@googlegroups.com
Did you try to use `xml:"Envelope"` ?

Regards,


Dmytro

Середа, 20 березня 2013 р. 22:44:42 UTC+2 користувач YardVox написав:

YardVox

unread,
Mar 20, 2013, 5:26:52 PM3/20/13
to golan...@googlegroups.com
Dmytro,
Thanks for your reponse.
Tried your suggestion after which I see the Envelope but the pointer to the soapBody is nil.
So in addition,  I tried your same idea on SoapBody and still the pointer to the soapBody is nil.

What am I missing other than json?

Dmytro

unread,
Mar 20, 2013, 6:04:51 PM3/20/13
to golan...@googlegroups.com
YardVox,

I think this willl help you.
http://www.w3schools.com/xml/xml_namespaces.asp
http://www.w3.org/TR/REC-xml-names/

Regards,

Dmytro

Середа, 20 березня 2013 р. 23:26:52 UTC+2 користувач YardVox написав:

YardVox

unread,
Mar 21, 2013, 10:14:04 AM3/21/13
to golan...@googlegroups.com
Dmytro,
I found a wonderful library
That handles Soap and solves my application problem.
I will attempt, when time permits you learn why this solution works and my Unmarshal attempt did not.


On Wednesday, March 20, 2013 4:44:42 PM UTC-4, YardVox wrote:

YardVox

unread,
Mar 21, 2013, 10:32:22 AM3/21/13
to golan...@googlegroups.com
Dmytro,
I reviewed your working code against my non-working code and found both my syntax and SoapConcepts error.
You were telling me to look at the "right side only" of the  soap prefix:postfix pair.
My coding now functions.  Thanks for all your time/efforts.

Rob


On Wednesday, March 20, 2013 4:44:42 PM UTC-4, YardVox wrote:

Russ Cox

unread,
Mar 21, 2013, 4:44:57 PM3/21/13
to YardVox, golang-nuts
For what it's worth, that's not valid XML you're passing into the function. "soap:" is a name space prefix, and the soap name space has not been defined at the place where it is used. If it had been defined, such as with a tag defining an attribute xmlns:soap="http://some/url/", then you could use `xml:"http://some/url/ Envelope"` to say that you are trying to match the Envelope tag, and only the one in the soap name space.

Russ

Dmytro

unread,
Mar 21, 2013, 5:48:19 PM3/21/13
to golan...@googlegroups.com, YardVox
Russ,

Does this code valid?



Regards,

Dmytro

Четвер, 21 березня 2013 р. 22:44:57 UTC+2 користувач Russ Cox написав:

YardVox

unread,
Mar 21, 2013, 7:01:17 PM3/21/13
to golan...@googlegroups.com
Russ, Dmyto,

I did leave out client stuff. The code below include sanitized xml stuff Russ said I was missing
coupled with Dmyto guidance on how to handle soap xml.

This code runs; Whether it is proper code following proper standards ... I do not know.


http://play.golang.org/p/7YLOQW-uig

RobS


On Wednesday, March 20, 2013 4:44:42 PM UTC-4, YardVox wrote:

Russ Cox

unread,
Mar 21, 2013, 9:17:36 PM3/21/13
to YardVox, golang-nuts
What you have is fine. If you needed to distinguish soap:Envelope from some other kind of Envelope, you'd want to qualify the tag with the URL identifying the name space: http://play.golang.org/p/17RT8VuCdu.

Russ

Dmytro

unread,
Mar 22, 2013, 7:43:38 AM3/22/13
to golan...@googlegroups.com, YardVox

I tried to parse this example from W3CSchools and got the error: expected element <table> in name space http://www.w3.org/TR/html4/ but have http://www.w3schools.com/furniture
So it looks like Unmarshal can't handle  tags with the same name even if they are in different namespaces.

xml:
<h:table>
  <h:tr>
    <h:td>Apples</h:td>
    <h:td>Bananas</h:td>
  </h:tr>
</h:table>
<f:table>
  <f:name>African Coffee Table</f:name>
  <f:width>80</f:width>
  <f:length>120</f:length>
</f:table>
</root>


Regards,

Dmytro

Пʼятниця, 22 березня 2013 р. 03:17:36 UTC+2 користувач Russ Cox написав:
Reply all
Reply to author
Forward
0 new messages