我是否应该能够定义一个包含 *string 的结构并使用它来解码 innerxml 内容。
示例请参见此处 https://play.golang.org/p/oaGu0rKYNgi
我希望 Struct 变量 Containment 指向
<top xmlns="http://example.com/schema/1.2/config"/>
相反,它是零。
我在 src/encoding/xml/marshal_test.go 中看到类似的示例结构
type IndirInnerXML struct {
T1 T1
InnerXML *string `xml:",innerxml"`
T2 T2
}
非常感谢任何帮助。
最佳答案
您引用的测试是针对Marshal
的,而不是针对Unmarshal
的。对于Unmarshal的innerxml没有测试*string
;有一个证明它不能与 []string
一起工作,但它可以与 []byte
和 string
一起工作,但是而已。根据the docs for Unmarshal
:
If the struct has a field of type
[]byte
orstring
with tag",innerxml"
, Unmarshal accumulates the raw XML nested inside the element in that field. The rest of the rules still apply.
它支持[]byte
和string
专门 用于解码内部XML。
是否支持 *string
是 Go 维护者的问题。
关于xml - 将 innerxml 解码为字符串指针,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51446722/