0

How can I add an XML element attribute from another struct?

For example: http://play.golang.org/p/E3K1KYnRH8

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.