FAQ
In your original post to stack overflow you wanted to unmarshal the XML to
map[string]interface{} - that's what github.com/clbanning/mxj is primarily
for ...
On Wednesday, June 4, 2014 3:48:29 PM UTC-5, Kyle Wolfe wrote:

Bringing my question in from stackoverflow as I believe I'm finding some
unexpected behavior:
http://stackoverflow.com/questions/24045497/encoding-xml-handle-unmapped-elements
From http://golang.org/pkg/encoding/xml/#Unmarshal

- If the XML element contains a sub-element that hasn't matched any
of the above rules and the struct has a field with tag ",any", unmarshal
maps the sub-element to that struct field.

If the XML element contains a sub-element that hasn't matched any of the
above rules and the struct has a field with tag ",any", unmarshal maps the
sub-element to that struct field.

I'm having trouble getting the remainder of an XML envelope into my
struct (to show that I have an incomplete mapping)

http://play.golang.org/p/mnFqAcguJQ

I know you can use exactly this method with bson.M from the mgo packages
using ,inline - but it looks like map[string]interface{} isn't the answer
here.

EDIT: After some additional playing, I've found what I believe to be some
additional unexpected behavior.

Switching to []string as a type starts to accept input, but no key/value
pairs: http://play.golang.org/p/wCAJeeQa4m

I also planned on adapting encode/xml in order to parse html. I do not
see in the documentation that if an element exists more than once, it will
save the last instance of it, rather than erroring out:
http://play.golang.org/p/0MY__R-Xi3
--
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/d/optout.

Search Discussions

  • Kyle Wolfe at Jul 21, 2014 at 1:35 pm

    On Saturday, July 19, 2014 7:45:40 AM UTC-4, C Banning wrote:
    In your original post to stack overflow you wanted to unmarshal the XML to
    map[string]interface{} - that's what github.com/clbanning/mxj is
    primarily for ...
    In my original post, my goal was simply to identify fields that were not
    successfully unmarshaled. Encoding/xml handles everything I need except for
    this, which I would think would be most useful. mxj doesn't really satisfy
    my requirements as I need to unmarshal into a struct, not an interface. I
    guess I'm trying to open dialog for an enhancement to encoding/xml.

    --
    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/d/optout.
  • Dan Kortschak at Jul 21, 2014 at 2:16 pm

    On Mon, 2014-07-21 at 06:34 -0700, Kyle Wolfe wrote:
    In my original post, my goal was simply to identify fields that were
    not successfully unmarshaled. Encoding/xml handles everything I need
    except for this, which I would think would be most useful. mxj doesn't
    really satisfy my requirements as I need to unmarshal into a struct,
    not an interface. I guess I'm trying to open dialog for an enhancement
    to encoding/xml.
    This should give you an idea about how to get what you want:

    http://play.golang.org/p/34ghqHbDHo

    It's brittle, but trivial to generalise.

    --
    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/d/optout.
  • Kyle Wolfe at Jul 21, 2014 at 2:18 pm
    But if I reference anything under c, it will not catch the unmatched within
    c.

    http://play.golang.org/p/se9KlLOVMe
    On Monday, July 21, 2014 10:16:18 AM UTC-4, kortschak wrote:
    On Mon, 2014-07-21 at 06:34 -0700, Kyle Wolfe wrote:
    In my original post, my goal was simply to identify fields that were
    not successfully unmarshaled. Encoding/xml handles everything I need
    except for this, which I would think would be most useful. mxj doesn't
    really satisfy my requirements as I need to unmarshal into a struct,
    not an interface. I guess I'm trying to open dialog for an enhancement
    to encoding/xml.
    This should give you an idea about how to get what you want:

    http://play.golang.org/p/34ghqHbDHo

    It's brittle, but trivial to generalise.
    --
    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/d/optout.
  • Chris Hines at Jul 21, 2014 at 10:52 pm
    This seems like: https://code.google.com/p/go/issues/detail?id=6901

    --
    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/d/optout.
  • Kyle Wolfe at Jul 22, 2014 at 1:39 pm
    Oh good, I did a search for an issue and didn't find this. What kind of
    attention to this issue can I expect since it was accepted? I added my own
    comment to it to draw attention.
    On Monday, July 21, 2014 6:52:21 PM UTC-4, Chris Hines wrote:

    This seems like: https://code.google.com/p/go/issues/detail?id=6901
    --
    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/d/optout.
  • Kyle Wolfe at Jul 21, 2014 at 6:57 pm
    Can someone explain how to use xml.StartElelemnt with DecodeElement(),
    maybe that will help me?

    --
    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/d/optout.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-nuts @
categoriesgo
postedJul 19, '14 at 11:45a
activeJul 22, '14 at 1:39p
posts7
users4
websitegolang.org

People

Translate

site design / logo © 2022 Grokbase