如何解码此 xml
<?xml version="1.0" encoding="UTF-8"?>
<LocationConstraint>oss-cn-hangzhou</LocationConstraint>
我的代码是这样的:
type BucketLocation struct {
LocationConstraint string `xml:"LocationConstraint"`
}
v := &BucketLocation{}
xml.Unmarshal(xml_content, v)
但是它不起作用。
最佳答案
您的结构的定义暗示了以下 XML 格式,该格式与您提供的内容不匹配:
<BucketLocation>
<LocationConstraint>oss-cn-hangzhou</LocationConstraint>
</BucketLocation>
要阅读您提供的示例 XML,您需要执行以下操作:
var v string
xml.Unmarshal(xml_content, &v)
关于xml - 如何 golang 将 xml 消息解码到结构中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33382610/