FAQ
With encoding/xml package the common way to unmarshal xml
"<tag>some_value</tag>" is to define a struct like
type A struct{
Tag string `tag`
}
and the value of A.Tag will be "some_value".

Now what I want is
type B struct{
Test bool
}
I'd like to have B.Test equal to true for xml "<true/>" and false for xml
"<false/>".

Is it possible?

Thanks
Andy

--

Search Discussions

  • Kyle Lemons at Sep 14, 2012 at 5:43 pm

    On Thu, Sep 13, 2012 at 9:32 PM, Andy W. Song wrote:

    With encoding/xml package the common way to unmarshal xml
    "<tag>some_value</tag>" is to define a struct like
    type A struct{
    Tag string `tag`
    }
    and the value of A.Tag will be "some_value".

    Now what I want is
    type B struct{
    Test bool
    }
    I'd like to have B.Test equal to true for xml "<true/>" and false for xml
    "<false/>".

    Is it possible?
    Nope. You'd need a *true and *false field, I suspect.

    Thanks
    Andy

    --

    --
  • Andy W. Song at Sep 15, 2012 at 6:18 am
    Yes you are right. I read the xml package doc again and it seems no way to
    have what I wanted.

    Thanks.
    On Sat, Sep 15, 2012 at 1:43 AM, Kyle Lemons wrote:
    On Thu, Sep 13, 2012 at 9:32 PM, Andy W. Song wrote:

    With encoding/xml package the common way to unmarshal xml
    "<tag>some_value</tag>" is to define a struct like
    type A struct{
    Tag string `tag`
    }
    and the value of A.Tag will be "some_value".

    Now what I want is
    type B struct{
    Test bool
    }
    I'd like to have B.Test equal to true for xml "<true/>" and false for xml
    "<false/>".

    Is it possible?
    Nope. You'd need a *true and *false field, I suspect.

    Thanks
    Andy

    --


    --
    ---------------------------------------------------------------
    有志者,事竟成,破釜沉舟,百二秦关终属楚
    苦心人,天不负,卧薪尝胆,三千越甲可吞吴

    --

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-nuts @
categoriesgo
postedSep 14, '12 at 4:33a
activeSep 15, '12 at 6:18a
posts3
users2
websitegolang.org

2 users in discussion

Andy W. Song: 2 posts Kyle Lemons: 1 post

People

Translate

site design / logo © 2022 Grokbase