chidley icon indicating copy to clipboard operation
chidley copied to clipboard

Unmarshal error with namespaced and non-namespaced XML Attributes

Open klauern opened this issue 7 years ago • 5 comments

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"

klauern avatar Feb 17 '17 13:02 klauern

https://play.golang.org/p/j8aIJtbwEm

klauern avatar Feb 17 '17 14:02 klauern

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.

klauern avatar Feb 17 '17 14:02 klauern

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.... :-(

gnewton avatar Feb 17 '17 14:02 gnewton

I am going to change this issue to "Document limitations of chidley due to limitations (bugs) in underlying go/xml marshalling/demarshalling".

gnewton avatar Feb 17 '17 14:02 gnewton

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.

gnewton avatar Feb 17 '17 15:02 gnewton