【发布时间】:2019-01-04 00:54:14
【问题描述】:
用gowsdl基于NetSuite SuiteTalk web service definition生成的一组类型:
<complexType name="TokenPassportSignature">
<simpleContent>
<extension base="xsd:string">
<attribute name="algorithm" type="xsd:string" use="required"/>
</extension>
</simpleContent>
</complexType>
<complexType name="TokenPassport">
<sequence>
<element name="account" type="xsd:string"/>
<element name="consumerKey" type="xsd:string"/>
<element name="token" type="xsd:string"/>
<element name="nonce" type="xsd:string"/>
<element name="timestamp" type="xsd:long"/>
<element name="signature" type="platformCore:TokenPassportSignature"/>
</sequence>
</complexType>
它创建了以下类型:
type TokenPassportSignature struct {
XMLName xml.Name `xml:"urn:core_2018_2.platform.webservices.netsuite.com TokenPassportSignature"`
Value string
Algorithm string `xml:"algorithm,attr,omitempty"`
}
type TokenPassport struct {
XMLName xml.Name `xml:"urn:core_2018_2.platform.webservices.netsuite.com TokenPassport"`
Account string `xml:"account,omitempty"`
ConsumerKey string `xml:"consumerKey,omitempty"`
Token string `xml:"token,omitempty"`
Nonce string `xml:"nonce,omitempty"`
Timestamp int64 `xml:"timestamp,omitempty"`
Signature *TokenPassportSignature `xml:"signature,omitempty"`
}
当我尝试通过客户端处理它时,XML 编码过程不喜欢 Signature 字段的名称冲突。
xml:main.TokenPassport.Signature 标记中的名称“signature”与 *main.TokenPassportSignature.XMLName 中的名称“TokenPassportSignature”冲突
我已经extracted out the relevant bits into Go Playground 确认这是引发错误的编码器。根据Marhsal 的文档,该字段似乎必须匹配:
如果结构字段的 XML 名称由字段标记定义 和结构的 XMLName 字段,名称必须匹配。
关于如何进行的任何想法?
【问题讨论】:
-
根据 un/marshaled 数据的外观,删除标记或 XMLName 字段,或编辑这两者之一以使其匹配。
-
... 这是一个example(我不确定您是否需要存在命名空间,所以我已将其添加到标签中)。还要注意
Value字段上的,chardata标记选项,没有它,封送拆收器将向签名元素添加一个内部元素,这不是你想要的。 -
感谢@mkopriva,这很有用。如果您将其添加为答案,我会将其标记为答案。