I'm trying to marshal and unmarshal a SOAP request that can have many different <Body> child tags. My thought was to do something like this:
type Envelope struct {
Body *Body
}
type Body struct {
Content interface{} `xml:",any"
}
type OneResult struct {
SomeValue string
}
Then *maybe* I could teach it how to unmarshal by assigning an object to Content, like so:
result := &OneResult{}
envelope := &Envelope{Body: &Body{Content: result}}
xml.Unmarshal(body, envelope)
fmt.Printf("Result = %#v\n", result)
So that if my SOAP request returned a body like this (I'm leaving out all the namespaces and attributes for brevity):
<Envelope>
<Body>
<OneResult>
<Value>Some Value</Value>
</OneResult>
</Body>
</Envelope>
I'd print out a instance of the OneResult object with a Value of "Some Value" inside. But this doesn't work.
I'm doing this because there could be hundreds of different SOAP responses, and I don't want a Body that looks like this:
type Body struct {
OneResult *OneResult `xml:",omitempty"`
TwoResult *OneResult `xml:",omitempty"`
ThreeResult *OneResult `xml:",omitempty"`
FourResult *OneResult `xml:",omitempty"`
FiveResult *OneResult `xml:",omitempty"`
SixResult *OneResult `xml:",omitempty"`
SevenResult *OneResult `xml:",omitempty"`
....
}
Is there any way to accomplish this with the Go XML unmarshaler?