mirror of
https://github.com/gin-gonic/gin.git
synced 2025-04-24 10:20:28 +08:00
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:
parent
51aea73ba0
commit
2ae5988db3
@ -26,8 +26,13 @@ func (xmlBinding) BindBody(body []byte, obj any) error {
|
||||
}
|
||||
func decodeXML(r io.Reader, obj any) error {
|
||||
decoder := xml.NewDecoder(r)
|
||||
if err := decoder.Decode(obj); err != nil {
|
||||
return err
|
||||
for {
|
||||
if err := decoder.Decode(obj); err != nil {
|
||||
if err == io.EOF{
|
||||
break
|
||||
}
|
||||
return err
|
||||
}
|
||||
}
|
||||
return validate(obj)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user