Skip to content

Instantly share code, notes, and snippets.

@marti1125
Created June 15, 2020 03:22
Show Gist options
  • Save marti1125/814083517314df24567bb2ea06df422c to your computer and use it in GitHub Desktop.
Save marti1125/814083517314df24567bb2ea06df422c to your computer and use it in GitHub Desktop.
xml parse
package main
import "fmt"
import "encoding/xml"
type MyRespEnvelope struct {
XMLName xml.Name
Body Body
}
type Body struct {
XMLName xml.Name
GetResponse completeResponse `xml:"activationPack_completeResponse"`
}
type completeResponse struct {
XMLName xml.Name `xml:"activationPack_completeResponse"`
Id string `xml:"Id,attr"`
MyVar string `xml:"activationPack_completeResult"`
}
func main() {
Soap := []byte(`<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/">
<soap:Body>
<activationPack_completeResponse Id="http://tempuri.org/">
<activationPack_completeResult xsi:type="xsd:string">Active</activationPack_completeResult>
</activationPack_completeResponse>
</soap:Body>
</soap:Envelope>`)
res := &MyRespEnvelope{}
err := xml.Unmarshal(Soap, res)
fmt.Println(res.Body, err)
fmt.Println(res.Body.GetResponse.MyVar, err)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment