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: XML attributes of child elements #5565

Closed
gopherbot opened this issue May 27, 2013 · 3 comments
Closed

encoding/xml: XML attributes of child elements #5565

gopherbot opened this issue May 27, 2013 · 3 comments
Milestone

Comments

@gopherbot
Copy link

by kyle@onnet.co.za:

Hi there

I am trying to access attributes of nested XML elements. The first element's attributes
are stored fine, but subsequent elements get missed. From the attached file, both
attributes of the "Tournament" element get stored, however any subsequent
elements like "Match" do not.

I have tried several ways to fix this:
type Tournament struct {
    BetradarTournamentId int `xml:",attr"` //This works
    UniqueTournamentId int `xml:",attr"` //This works
    Name string `xml:"Name"`
    Match []Match `xml:"Match"`
}

type Match struct {
    BetradarMatchId int `xml: ",attr"` //This doesnt work
    previouslegmatchid []xml.Attr `xml: ",attr"` //This doesnt work
    Id int `xml: "Id,attr"` //This doesnt work
    ...
}

There seems to be a bug related to this -
https://golang.org/issue/3633

Is there any way I can store these attributes correctly? I am running Go v1.1.

Thanks in advance

Attachments:

  1. data.xml (1100 bytes)
@rsc
Copy link
Contributor

rsc commented Jul 30, 2013

Comment 2:

Labels changed: added priority-later, go1.2maybe, removed priority-triage.

Status changed to Accepted.

@rsc
Copy link
Contributor

rsc commented Jul 30, 2013

Comment 3:

Labels changed: added feature.

@rsc
Copy link
Contributor

rsc commented Aug 13, 2013

Comment 4:

http://play.golang.org/p/8LJYerWMOm seems to work.
There are two problems with the snippet you posted. One is that you have a space between
the : and " in `xml: ",attr"` in a few of the places. The other is that
previouslegmatchid is unexported.

Status changed to WorkingAsIntended.

@rsc rsc added this to the Go1.2 milestone Apr 14, 2015
@rsc rsc removed the go1.2maybe label Apr 14, 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

2 participants