FAQ
Hi,

If attributes are present in xml as below:
<A>
<B Attr1="val1"/>
</A>

To Unmarshal, Go struct definition seem to require:

type A struct { B B }
type B struct { Attr1 string `xml:",attr"` }

Instead I would like to have it as:
type A struct {
Attr1 string `some_mapping_directive`
}

Is this possible?

thanks
Shivakumar GN

--

Search Discussions

  • Scott Lawrence at Jan 26, 2013 at 4:06 pm

    On Sat, 26 Jan 2013, Shivakumar GN wrote:

    Hi,

    If attributes are present in xml as below:
    <A>
    <B Attr1="val1"/>
    </A>

    To Unmarshal, Go struct definition seem to require:

    type A struct { B B }
    type B struct { Attr1 string `xml:",attr"` }

    Instead I would like to have it as:
    type A struct {
    Attr1 string `some_mapping_directive`
    }

    Is this possible?
    I would guess something like

    Attr1 string `B>,attr`

    would accomplish it, if anything.
    thanks
    Shivakumar GN

    --

    --
    Scott Lawrence

    go version go1.0.3
    Linux baidar 3.7.4-1-ARCH #1 SMP PREEMPT Mon Jan 21 23:05:29 CET 2013 x86_64 GNU/Linux

    --
  • Shivakumar GN at Jan 26, 2013 at 4:34 pm

    On Sat, Jan 26, 2013 at 9:34 PM, Scott Lawrence wrote:
    I would guess something like

    Attr1 string `B>,attr`

    would accomplish it, if anything.

    Checked this - this still comes down to the same 2 structs but with
    slightly different syntax.
    The `B>, attr` is not helping eliminate one of the structs.

    --
  • Ernest Micklei at Jan 28, 2013 at 12:29 pm
    Op zaterdag 26 januari 2013 17:34:39 UTC+1 schreef Shivakumar GN het
    volgende:

    On Sat, Jan 26, 2013 at 9:34 PM, Scott Lawrence <byt...@gmail.com<javascript:>
    wrote:

    I would guess something like

    Attr1 string `B>,attr`

    would accomplish it, if anything.

    Checked this - this still comes down to the same 2 structs but with
    slightly different syntax.
    The `B>, attr` is not helping eliminate one of the structs.

    still not eliminating the B struct but the following will encapsulate it
    type A struct {
    B struct {
    Attr1 string `xml:",attr"`
    }
    }

    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group, send email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
  • Shivakumar GN at Jan 28, 2013 at 5:14 pm
    Thanks.

    After going through the encoding/xml package, I came to the conclusion that
    flat hierarchy mapping is not feasible directly via Unmarshal.

    I had some complex xmls that required schema change and I intended to do as
    much as possible with Unmarshal itself.
    Instead I did the schema change after Unmarshal.

    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group, send email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
  • Kyle Lemons at Jan 28, 2013 at 6:27 pm
    Hierarchical remapping is certainly possible with the struct tags, but I
    don't think it works with attributes.

    On Mon, Jan 28, 2013 at 9:14 AM, Shivakumar GN wrote:

    Thanks.

    After going through the encoding/xml package, I came to the conclusion
    that flat hierarchy mapping is not feasible directly via Unmarshal.

    I had some complex xmls that required schema change and I intended to do
    as much as possible with Unmarshal itself.
    Instead I did the schema change after Unmarshal.

    --
    You received this message because you are subscribed to the Google Groups
    "golang-nuts" group.
    To unsubscribe from this group, send email to
    golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.

    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group, send 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
postedJan 26, '13 at 3:44p
activeJan 28, '13 at 6:27p
posts6
users4
websitegolang.org

People

Translate

site design / logo © 2021 Grokbase