I've been trying to parse an xml in Go by defining structs and using xml.Unmarshal like this:
type InitiateResponse struct {
SoapenvEnvelope struct {
SoapenvBody struct {
ReqResponseMsg struct {
CData struct {
Response struct {
ResponseCode string `xml:"ResponseCode"`
ConversationID string `xml:"ConversationID"`
ResponseDesc string `xml:"ResponseDesc"`
OriginatorConversationID string `xml:"OriginatorConversationID"`
ServiceStatus string `xml:"ServiceStatus"`
} `xml:"req:Response"`
} `xml: ![CDATA[`
} `xml:"req:ResponseMsg"`
} `xml:"soapenv:Body"`
} `xml:"soapenv:Envelope"`
}
var unit InitiateResponse
if err := xml.Unmarshal([]byte(data), &unit); err != nil {
fmt.Println(err)
return
}
There's no error thrown but the struct is always empty at the end. Can't understand why.
This is the xml:
<?xml version='1.0' encoding='UTF-8'?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:req="http://cps.huawei.com/cpsinterface/request">
<soapenv:Header />
<soapenv:Body>
<req:ResponseMsg><![CDATA[<?xml version="1.0" encoding="UTF-8"?><Response><ResponseCode>14</ResponseCode><ConversationID>AG_20170222_000040cdc5cecf730e39</ConversationID><ResponseDesc>The caller information is invalid.</ResponseDesc><OriginatorConversationID>S_X2013012921001</OriginatorConversationID><ServiceStatus>2</ServiceStatus></Response>]]></req:ResponseMsg>
</soapenv:Body>
</soapenv:Envelope>
Check it out: https://play.golang.org/p/Irmy8AsUKa