chidley
chidley copied to clipboard
Unmarshal error with namespaced and non-namespaced XML Attributes
You're probably loving all of these issues...Sorry about that.
I found something that I'm not sure if it's a Go encoding/xml
error, or if there's something wrong with my XML. The following piece of XML
<ser:binding type="SOAP" isSoap12="false" xsi:type="con:SoapBindingType" xmlns:con="http://www.bea.com/wli/sb/services/bindings/config" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<!-- other nested items -->
...
</ser:binding>
Generates the following struct:
type Chiser_binding struct {
Attr_con string `xml:"xmlns con,attr" json:",omitempty"`
Attr_isSoap12 string `xml:"isSoap12,attr" json:",omitempty"`
Attr_type string `xml:" type,attr" json:",omitempty"`
Attr_xsi_type string `xml:"http://www.w3.org/2001/XMLSchema-instance type,attr" json:",omitempty"`
Attr_xsi string `xml:"xmlns xsi,attr" json:",omitempty"`
Chicon_WSI_compliant *Chicon_WSI_compliant `xml:"http://www.bea.com/wli/sb/services/bindings/config WSI-compliant,omitempty" json:"WSI-compliant,omitempty"`
Chicon_port *Chicon_port `xml:"http://www.bea.com/wli/sb/services/bindings/config port,omitempty" json:"port,omitempty"`
Chicon_selector *Chicon_selector `xml:"http://www.bea.com/wli/sb/services/bindings/config selector,omitempty" json:"selector,omitempty"`
Chicon_wsdl *Chicon_wsdl `xml:"http://www.bea.com/wli/sb/services/bindings/config wsdl,omitempty" json:"wsdl,omitempty"`
XMLName xml.Name `xml:"http://www.bea.com/wli/sb/services binding,omitempty" json:"binding,omitempty"`
}
However, when I unmarshal, I get the following error:
proxy_test.go:18: lint.Chiser_binding field "Attr_type" with tag " type,attr" conflicts with field "Attr_xsi_type" with tag "http://www.w3.org/2001/XMLSchema-instance type,attr"
https://play.golang.org/p/j8aIJtbwEm
Okay, I think this is a Go issue: golang/go#13400 . There appear to be many issues with namespaces in there, and in particular, golang/go#8535 that points to this one.
Yes, there are issues in go/xml's ability to handle namespaces. I have commented either in one of those many issues or in the golang list (quite a while ago, like a year). I will add this external limitation to the chidley 'Limitations' section.
They really are showstoppers for anyone who wants to do serious XML.... :-(
I am going to change this issue to "Document limitations of chidley due to limitations (bugs) in underlying go/xml marshalling/demarshalling".
Note in https://github.com/golang/go/issues/13400 indicates Milestone Go1.9Early, Go1.8
, but it clearly did no make in into 1.8, as per release notes https://beta.golang.org/doc/go1.8 the only changes to go/xml:
encoding/xml
Unmarshal now has wildcard support for collecting all attributes using the new ",any,attr" struct tag.