繁体   English   中英

如何使用golang将xml消息解组到结构中

[英]how to golang Unmarshal a xml message into a struct

如何解码这个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格式不匹配的XML格式:

<BucketLocation>
    <LocationConstraint>oss-cn-hangzhou</LocationConstraint>
</BucketLocation>

要阅读您提供的示例XML,请执行以下操作:

var v string
xml.Unmarshal(xml_content, &v)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM