FAQ
How can I write an xml structure that has both attribute value and tag data
i.e. <tag a="ATTR_VALUE">TAG_DATA</tag> . I'm new to Go and am not sure how
to get this to work.

I want to get this

<Item_group>
<item key="a">11</item>
...
</item_group>

I couldn't find any examples on this online. I'm pretty sure I'm missing
something here. *Ideas*? *Examples* I can see online? Any help is
appreciated.

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

Search Discussions

  • Shivakumar GN at Feb 2, 2013 at 4:14 am

    On Sat, Feb 2, 2013 at 6:55 AM, wrote:

    How can I write an xml structure that has both attribute value and tag
    data i.e. <tag a="ATTR_VALUE">TAG_DATA</tag> . I'm new to Go and am not
    sure how to get this to work.

    I want to get this

    <Item_group>
    <item key="a">11</item>
    ...
    </item_group>

    I couldn't find any examples on this online. I'm pretty sure I'm missing
    something here. *Ideas*? *Examples* I can see online? Any help is
    appreciated.
    Does this example address the point:
    http://golang.org/pkg/encoding/xml/#example_MarshalIndent

    Same example in executable form:
    http://play.golang.org/p/NTTncYfRli

    --
    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+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
  • Nkothap at Feb 3, 2013 at 5:54 am
    Not really. I want to know how to write something like this <item
    key="a">10</item>. I have the following, which is evidently wrong (<item
    key ="a"><item>10</item></item> is what I get ) but I am not sure how to
    get it right.

    type XMLItem struct {
    XMLName xml.Name `xml:"item"`
    Item int `xml:item`
    Key string `xml:"key,attr"`

    }

    v := &Item{Key: "a", Item: 10}
    On Friday, February 1, 2013 9:14:24 PM UTC-7, Shivakumar GN wrote:
    On Sat, Feb 2, 2013 at 6:55 AM, <nko...@gmail.com <javascript:>> wrote:

    How can I write an xml structure that has both attribute value and tag
    data i.e. <tag a="ATTR_VALUE">TAG_DATA</tag> . I'm new to Go and am not
    sure how to get this to work.

    I want to get this

    <Item_group>
    <item key="a">11</item>
    ...
    </item_group>

    I couldn't find any examples on this online. I'm pretty sure I'm missing
    something here. *Ideas*? *Examples* I can see online? Any help is
    appreciated.
    Does this example address the point:
    http://golang.org/pkg/encoding/xml/#example_MarshalIndent

    Same example in executable form:
    http://play.golang.org/p/NTTncYfRli
    --
    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+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
  • Shivakumar GN at Feb 3, 2013 at 11:41 am
    Does this help?:

    type ItemGroup struct {
    ItemAttr string `xml:"ItemGroup>Item,attr"`
    Value string `xml:",chardata"`
    }

    func main() {
    v := &ItemGroup{ItemAttr: "attr", Value: "myval"}
    data, _ := xml.Marshal(v)
    fmt.Println(string(data))
    }

    Output:
    <ItemGroup Item="attr">myval</ItemGroup>

    --
    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+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
  • Nkothap at Feb 4, 2013 at 4:25 pm
    That worked. Thanks a lot!
    On Sunday, February 3, 2013 4:41:16 AM UTC-7, Shivakumar GN wrote:

    Does this help?:

    type ItemGroup struct {
    ItemAttr string `xml:"ItemGroup>Item,attr"`
    Value string `xml:",chardata"`
    }

    func main() {
    v := &ItemGroup{ItemAttr: "attr", Value: "myval"}
    data, _ := xml.Marshal(v)
    fmt.Println(string(data))
    }

    Output:
    <ItemGroup Item="attr">myval</ItemGroup>

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

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-nuts @
categoriesgo
postedFeb 2, '13 at 1:25a
activeFeb 4, '13 at 4:25p
posts5
users2
websitegolang.org

2 users in discussion

Nkothap: 3 posts Shivakumar GN: 2 posts

People

Translate

site design / logo © 2022 Grokbase