Reputation: 11
How can I add an XML element attribute from another struct?
For example: http://play.golang.org/p/E3K1KYnRH8
Upvotes: 0
Views: 473
Reputation: 36279
Embed the type with common attrs into your other types.
type AuthData struct {
BuyerId string `xml:"BuyerId,attr"`
UserId string `xml:"UserId,attr"`
Language string `xml:"Language,attr"`
}
type MyRequest struct {
XMLName xml.Name `xml:"MyRequest"`
AuthData // Embedding.
Action struct{} `xml:"Action"`
}
Playground: http://play.golang.org/p/u23HuwYgq2.
Upvotes: 1