Skip to content
New issue

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

xml:how to check point to nil when xml Unmarshal #60736

Closed
ChuLiqiang opened this issue Jun 12, 2023 · 1 comment
Closed

xml:how to check point to nil when xml Unmarshal #60736

ChuLiqiang opened this issue Jun 12, 2023 · 1 comment

Comments

@ChuLiqiang
Copy link

when some value is <tt:PTZPosition /> how can I check the value is nil when xml Unmarshal. I try use pointer.but the value is not nil(Zoom attributes is 0 I can not confirm 0 value is pass by xml value).

Example code:https://go.dev/play/p/BrgD4S--Rmf

code:
package main

import (
"encoding/xml"
"fmt"
)

type Vector1D struct {
X float64 xml:"x,attr"
}

type PTZVector struct {
Zoom Vector1D xml:"Zoom"
}

type PTZPresetTourPresetDetailUnmarshal struct {
PTZPosition *PTZVector xml:"PTZPosition"
}

func main() {
str := <tt:PresetDetail> <tt:PTZPosition /> </tt:PresetDetail>
var ans PTZPresetTourPresetDetailUnmarshal
err := xml.Unmarshal([]byte(str), &ans)
if err != nil {
panic(err)
}
fmt.Printf(%#v, ans.PTZPosition)
}

result:
&main.PTZVector{Zoom:main.Vector1D{X:0}}

@ChuLiqiang ChuLiqiang changed the title how to check point to nil when xml Unmarshal xml:how to check point to nil when xml Unmarshal Jun 12, 2023
@seankhliao
Copy link
Member

Unlike many projects, the Go project does not use GitHub Issues for general discussion or asking questions. GitHub Issues are used for tracking bugs and proposals only.

For questions please refer to https://github.com/golang/go/wiki/Questions

@seankhliao seankhliao closed this as not planned Won't fix, can't repro, duplicate, stale Jun 12, 2023
@golang golang locked and limited conversation to collaborators Jun 11, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants