I would like to unmarshall the value of an attribute X of specific node N to a struct field. Something like this:
var data = `<A id="A_ID">
<B id="B_ID">Something</B>
</A>
`
type A struct {
Id string `xml:"id,attr"` // A_ID
Name string `xml:"B.id,attr"` // B_ID
}
http://play.golang.org/p/U6daYJWVUX
As far as I was able to check this is not supported by Go. Am I correct, or am I missing something here?
In your question you are not mentioning B
. I'm guessing that you need to unmarshal its attr into A.Name
? If so - you could change your A struct to something like this:
type A struct {
Id string `xml:"id,attr"` // A_ID
Name struct {
Id string `xml:"id,attr"` // B_ID
} `xml:"B"`
}
Or maybe even better - define separate B struct:
type A struct {
Id string `xml:"id,attr"` // A_ID
Name B `xml:"B"`
}
type B struct {
Id string `xml:"id,attr"` // B_ID
}