Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

encoding/xml: Marshal doesn't understand "parent>child" struct tags #2119

Closed
mark-summerfield opened this issue Jul 30, 2011 · 4 comments
Closed

Comments

@mark-summerfield
Copy link

Build & run the two attached tiny examples and you'll see the problem. (The first
example is based on the Email/Results example in the xml package's documentation.)

I expect xml.Unmarshal to correctly read a data structure that was correctly written
with xml.Marshal.

Which compiler are you using (5g, 6g, 8g, gccgo)?

6g

Which operating system are you using?

Linux 64-bit (debian & Ubuntu)

Which revision are you using?  (hg identify)

I tried with 2 same results for both:
3c21f37b25a3+ weekly.2011-07-19
bb28251f6da4 weekly/weekly.2011-07-29


See also https://golang.org/issue/1989

Attachments:

  1. xmltest1.go (1232 bytes)
  2. xmltest2.go (1754 bytes)
@adg
Copy link
Contributor

adg commented Jul 30, 2011

Comment 1:

The problem is that the data isn't correctly written by xml.Marshal in the first place.
It seems the "parent>child" form in the struct tag doesn't work with xml.Marshal. The
program xmltest1.go generates invalid xml for this data structure:
 Result struct {
    // other fields omitted
    Groups  []string `xml:"group>value"`
}
<result>...omitted...<group>value>Friends</group>value><group>value>Squash</group>value></result>
When I manually fix up the invalid tags here, xml.Unmarshal correctly loads the contents
of the value elements into the Groups slice.

Status changed to Accepted.

@mark-summerfield
Copy link
Author

Comment 2:

The summary name change is wrong. If you try xmltest2.go you will see that it does not
use the "parent>child" syntax -- and yet it still fails to work correctly.
So perhaps this should be split into two separate bugs?

@zombiezen
Copy link
Contributor

Comment 3:

I ran into this problem myself, and I wrote a quick patch for it.  It works for my needs.
http://golang.org/cl/4941042

@niemeyer
Copy link
Contributor

Comment 4:

This issue was closed by revision 4541fa9.

Status changed to Fixed.

@mikioh mikioh changed the title xml.Marshal doesn't understand "parent>child" struct tags encoding/xml: Marshal doesn't understand "parent>child" struct tags Jan 9, 2015
@golang golang locked and limited conversation to collaborators Jun 24, 2016
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants