From 0c3d7b7e92eb273b1d9f243ef7a25e1b81559453 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BD=E8=8C=B6=E6=B8=85=E6=AC=A2?= Date: Sat, 3 May 2025 19:45:48 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8D=87=E7=BA=A7xml=E8=A7=A3=E6=9E=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- go.mod | 10 +++++++--- go.sum | 2 ++ xml.go | 7 ++++++- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/go.mod b/go.mod index 281cca4..986ef6e 100644 --- a/go.mod +++ b/go.mod @@ -5,10 +5,14 @@ go 1.23.0 toolchain go1.24.2 require ( + git.zhangdeman.cn/zhangdeman/consts v0.0.0-20250425024726-cc17224cb995 git.zhangdeman.cn/zhangdeman/util v0.0.0-20240618042405-6ee2c904644e github.com/BurntSushi/toml v1.5.0 github.com/go-ini/ini v1.67.0 gopkg.in/yaml.v3 v3.0.1 - git.zhangdeman.cn/zhangdeman/consts v0.0.0-20250425024726-cc17224cb995 - github.com/stretchr/testify v1.9.0 // indirect - ) +) + +require ( + github.com/sbabiv/xml2map v1.2.1 // indirect + github.com/stretchr/testify v1.9.0 // indirect +) diff --git a/go.sum b/go.sum index 319feaf..c84956c 100644 --- a/go.sum +++ b/go.sum @@ -14,6 +14,8 @@ github.com/jtolds/gls v4.20.0+incompatible h1:xdiiI2gbIgH/gLH7ADydsJ1uDOEzR8yvV7 github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/sbabiv/xml2map v1.2.1 h1:1lT7t0hhUvXZCkdxqtq4n8/ZCnwLWGq4rDuDv5XOoFE= +github.com/sbabiv/xml2map v1.2.1/go.mod h1:2TPoAfcaM7+Sd4iriPvzyntb2mx7GY+kkQpB/GQa/eo= github.com/smarty/assertions v1.15.0 h1:cR//PqUBUiQRakZWqBiFFQ9wb8emQGDb0HeGdqGByCY= github.com/smarty/assertions v1.15.0/go.mod h1:yABtdzeQs6l1brC900WlRNwj6ZR55d7B+E8C6HtKdec= github.com/smartystreets/goconvey v1.8.1 h1:qGjIddxOk4grTu9JPOU31tVfq3cNdBlNa5sSznIX1xY= diff --git a/xml.go b/xml.go index 97fb295..daeaeba 100644 --- a/xml.go +++ b/xml.go @@ -10,6 +10,7 @@ package serialize import ( "bytes" "encoding/xml" + "github.com/sbabiv/xml2map" "io" ) @@ -20,7 +21,11 @@ var ( type ownXml struct{} func (o *ownXml) UnmarshalWithNumber(byteData []byte, receiver any) error { - return xml.NewDecoder(bytes.NewReader(byteData)).Decode(receiver) + res, err := xml2map.NewDecoder(bytes.NewReader(byteData)).Decode() + if nil != err { + return err + } + return JSON.Transition(res, receiver) } func (o *ownXml) UnmarshalWithNumberIgnoreError(byteData []byte, receiver any) {