XML Marshal with namespaces

901 views
Skip to first unread message

qeed...@gmail.com

unread,
Jun 18, 2013, 9:05:33 PM6/18/13
to golan...@googlegroups.com
I am trying to decode some messages with xml and found the Unmarshal works with namespaces, but when I use Marshal on the same struct, I lose the namespace ie,
<foo:bar xmlns="..."> becomes <bar xmlns="...">, is there anyway I could get foo in the Marshal'ed xml version? Thanks.

Hydra Ea

unread,
Jun 18, 2013, 10:57:41 PM6/18/13
to golan...@googlegroups.com, qeed...@gmail.com
You can see the code. https://gist.github.com/eahydra/5336498
Maybe it can help you.

在 2013年6月19日星期三UTC+8上午9时05分33秒,qeed...@gmail.com写道:

Matt Jibson

unread,
Jun 18, 2013, 11:02:53 PM6/18/13
to qeed...@gmail.com, golang-nuts
Put the namespace before the tag name:

HTable string `xml:"http://www.w3.org/TR/html4/ table"`

See the xml test file for examples: http://golang.org/src/pkg/encoding/xml/read_test.go


On Tue, Jun 18, 2013 at 9:05 PM, <qeed...@gmail.com> wrote:
I am trying to decode some messages with xml and found the Unmarshal works with namespaces, but when I use Marshal on the same struct, I lose the namespace ie,
<foo:bar xmlns="..."> becomes <bar xmlns="...">, is there anyway I could get foo in the Marshal'ed xml version? Thanks.

--
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...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

qeed...@gmail.com

unread,
Jun 18, 2013, 11:12:03 PM6/18/13
to golan...@googlegroups.com, qeed...@gmail.com

I tried that from an example I found on the mailing list, it didn't do it for me: http://play.golang.org/p/W6KeEmQ4sS
Reply all
Reply to author
Forward
0 new messages