xml - 将 innerxml 解码为字符串指针

标签 xml go

我是否应该能够定义一个包含 *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 一起工作,但它可以与 []bytestring 一起工作,但是而已。根据the docs for Unmarshal :

If the struct has a field of type []byte or string with tag ",innerxml", Unmarshal accumulates the raw XML nested inside the element in that field. The rest of the rules still apply.

它支持[]bytestring 专门 用于解码内部XML。 是否支持 *string 是 Go 维护者的问题。

关于xml - 将 innerxml 解码为字符串指针,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51446722/

相关文章:

python - 如何使用 Python 在 XML 中搜索和替换?

java - DrawerLayout 和 NavigationView - 未找到属性 'menu'

go - Go 练习 #18 : Slices, 索引超出范围

go - 在 Viper 中使用 ENV 变量覆盖配置的问题

go - 从 Go 更改父 shell 目录

Java - 使用 JAXB API 从 JAXBElement 获取 XML 内容

c# - 由于格式化,XML 反序列化在十进制解析时崩溃

php - 如何更改 simpleXML 元素的属性值?

go - 无法将简单的golang项目推送到heroku

go - 如何为一元 rpc 定义响应 header