I have some code. I want get elem NoSessionException dynamically, because I have few xml responses with different exceptions. How can I to do it?
package main
import (
"encoding/xml"
"fmt"
)
type E struct {
XMLName xml.Name `xml:"Envelope"`
Body struct {
F TestFaultType `xml:"Fault"`
}
}
type TestFaultType struct {
FaultCode string `xml:"faultcode"`
FaultString string `xml:"faultstring"`
Detail string `xml:"detail>ns2"`
}
var data = []byte(`<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
<S:Body>
<S:Fault xmlns:ns4="http://www.w3.org/2003/05/soap-envelope">
<faultcode>S:Server</faultcode>
<faultstring>ffffffff</faultstring>
<detail>
<ns2:NoSessionException message="fffffff." xmlns:ns2="http://test.testing.testing.avilex.ru/"/>
</detail>
</S:Fault>
</S:Body>
</S:Envelope>`)
func main() {
var q E
xml.Unmarshal(data, &q)
fmt.Println(q)
}
I try to generate different structures but I want to find beautiful decision