XML转struct

text := <soap:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
    <soap:Header>
    </soap:Header>
    <soap:Body> 
    </soap:Body>
  </soap:Envelope>

type Envelope struct {
    XMLName      xml.Name `xml:"soap:Envelope"`
    EnvelopeAttr string   `xml:"xmlns:soap,attr"`
    XSDAttr      string   `xml:"xmlns:xsd,attr"`
    SOAPENVAttr  string   `xml:"xmlns:SOAP-ENV,attr"`
    SOAPENCAttr  string   `xml:"xmlns:SOAP-ENC,attr"`
    TNSAttr      string   `xml:"xmlns:tns,attr,omitempty"`
    URNAttr      string   `xml:"xmlns:urn,attr,omitempty"`
    XSIAttr      string   `xml:"xmlns:xsi,attr,omitempty"`
    Header       Header   `xml:"soap:Header"`
    Body         Message  `xml:"soap:Body"`
}



err := xml.Unmarshal([]byte(text), &envelope)
    if err != nil {
        fmt.Println(err)
    }


错误信息:expected element type <soap:Envelope> but have <Envelope>

为什么实际是<Envelope>,不是 <soap:Envelope>

共 1 个回复