Update xml.go

here is xml.Unmarshal problem if xml have muti-root:

[unmarshal-xml-array-in-golang-only-getting-the-first-element](https://stackoverflow.com/questions/27553274/unmarshal-xml-array-in-golang-only-getting-the-first-element)

[so  gin have same problem](https://stackoverflow.com/questions/74226570/golang-gin-binding-request-body-xml-to-slice):

if gin bind muti-root-xml, it should use for util io.EOF
This commit is contained in:
pzx521521 2022-10-28 14:28:08 +08:00 committed by GitHub
parent 51aea73ba0
commit 2ae5988db3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -26,8 +26,13 @@ func (xmlBinding) BindBody(body []byte, obj any) error {
} }
func decodeXML(r io.Reader, obj any) error { func decodeXML(r io.Reader, obj any) error {
decoder := xml.NewDecoder(r) decoder := xml.NewDecoder(r)
for {
if err := decoder.Decode(obj); err != nil { if err := decoder.Decode(obj); err != nil {
if err == io.EOF{
break
}
return err return err
} }
}
return validate(obj) return validate(obj)
} }