Golang marshal dynamic xml element name

我是研究僧i 提交于 2019-11-29 11:56:42

In the documentation, it says that the XMLName field must be of type xml.Name.

type Person struct {
    XMLName xml.Name
    E1 string `xml:"ELEM1"`
    // ...
}

Set the element name via the Local field of xml.Name:

person := Person { 
    XMLName: xml.Name { Local: "Person" },
    // ...
}

(Also, E1 - E4 must be exported in order to be included in the XML output).

Playground example: http://play.golang.org/p/bzSutFF9Bo

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!