We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
go version
$ go version go version go1.18.1 linux/amd64
maybe not?
go env
$ go env GO111MODULE="" GOARCH="amd64" GOBIN="" GOCACHE="/home/speauty/.cache/go-build" GOENV="/home/speauty/.config/go/env" GOEXE="" GOEXPERIMENT="" GOFLAGS="" GOHOSTARCH="amd64" GOHOSTOS="linux" GOINSECURE="" GOMODCACHE="/home/speauty/go/pkg/mod" GONOPROXY="" GONOSUMDB="" GOOS="linux" GOPATH="/home/speauty/go" GOPRIVATE="" GOPROXY="https://goproxy.cn" GOROOT="/usr/local/go" GOSUMDB="sum.golang.org" GOTMPDIR="" GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64" GOVCS="" GOVERSION="go1.18.1" GCCGO="gccgo" GOAMD64="v1" AR="ar" CC="gcc" CXX="g++" CGO_ENABLED="1" GOMOD="/dev/null" GOWORK="" CGO_CFLAGS="-g -O2" CGO_CPPFLAGS="" CGO_CXXFLAGS="-g -O2" CGO_FFLAGS="-g -O2" CGO_LDFLAGS="-g -O2" PKG_CONFIG="pkg-config" GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build1154348162=/tmp/go-build -gno-record-gcc-switches"
I want to parse a xml data from a xml file to a related struct by using encoding/xml lib.
that struct has all data parsed from xml, including attr.
struct is right, but the field binding to pointed attr flag is empty, no data with that.
the xml file data like follow:
<ProducData_ExpXML> <IronInfo OrderNo="220629192669300" /> </ProducData_ExpXML>
and code, emmm
type XmlExp struct { XMLName xml.Name `xml:"ProducData_ExpXML"` IronInfo IronInfo } type IronInfo struct { OrderNo string `xml:"OrderNo.attr"` } func (controller Common) UploadXml(ctx *gin.Context) { // gin web handle tmpXML, _ := ctx.FormFile("xml") xmlParsed := &XmlExp{} open, err := tmpXML.Open() defer func() { _ = open.Close() }() if err != nil { fmt.Println("file open", err) } data, _ := io.ReadAll(open) err = xml.Unmarshal(data, xmlParsed) if err != nil { fmt.Println("xml unmarshal", err) } resp := (&http.JsonResponse{}).Default() resp.SetData(map[string]interface{}{ "xml_parsed": xmlParsed, }) controller.Response(ctx, resp, nil) return }
of course, response is:
{ "c": 200, "m": "ok", "d": { "xml_parsed": { "XMLName": { "Space": "", "Local": "ProducData_ExpXML" }, "IronInfo": { "OrderNo": "" } } } }
the go-play link is: https://go.dev/play/p/bc2tww7J4wQ, which just simplified the above code.
The text was updated successfully, but these errors were encountered:
No branches or pull requests
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
maybe not?
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
I want to parse a xml data from a xml file to a related struct by using encoding/xml lib.
What did you expect to see?
that struct has all data parsed from xml, including attr.
What did you see instead?
struct is right, but the field binding to pointed attr flag is empty, no data with that.
the xml file data like follow:
and code, emmm
of course, response is:
the go-play link is: https://go.dev/play/p/bc2tww7J4wQ, which just simplified the above code.
The text was updated successfully, but these errors were encountered: