Mapping extra XML attributes

300 views
Skip to first unread message

Matt Joiner

unread,
May 31, 2012, 8:47:14 AM5/31/12
to golan...@googlegroups.com
I'm trying to marshal an XML element with arbitrary attributes. I want to decide when to omit certain attributes at runtime. To do this I'm assuming that some kind of map or slice of attributes is required but neither []xml.Attr nor any other intuitive types are handled for this purpose. Can anyone explain how to marshal optional attributes to an element at runtime?

I have a standing SO question for this too: http://stackoverflow.com/q/10828187/149482

Cheers

Kyle Lemons

unread,
May 31, 2012, 11:49:38 AM5/31/12
to Matt Joiner, golan...@googlegroups.com
On Thu, May 31, 2012 at 5:47 AM, Matt Joiner <anac...@gmail.com> wrote:
I'm trying to marshal an XML element with arbitrary attributes. I want to decide when to omit certain attributes at runtime. To do this I'm assuming that some kind of map or slice of attributes is required but neither []xml.Attr nor any other intuitive types are handled for this purpose. Can anyone explain how to marshal optional attributes to an element at runtime?

I have a standing SO question for this too: http://stackoverflow.com/q/10828187/149482

Have you tried ,omitempty on the attr?  I'm not positive that it will work, but I know the omitempty logic exists in xml.
 
Cheers

Matt Joiner

unread,
Jul 4, 2012, 8:50:20 AM7/4/12
to Kyle Lemons, golan...@googlegroups.com
I don't think omitempty is what I'm after.

Kyle Lemons

unread,
Jul 5, 2012, 2:19:16 AM7/5/12
to Matt Joiner, golan...@googlegroups.com
You'll have to expand upon what you're looking for.


That omits attributes that are set to their zero value.
Reply all
Reply to author
Forward
0 new messages