1 回答
TA贡献1866条经验 获得超5个赞
转义<
和>
字符对于有效的 XML 是必须的。别担心, 的内容<message>
将是This is <myText>
,但此文本必须出现在This is <myText>
XML 源中。
请注意,使用xml:",innerxml"
标记值,您可以强制输出原始 XML 数据,如记录在xml.Marshal()
:
- a field with tag ",innerxml" is written verbatim, not subject
to the usual marshaling procedure.
像这样:
type rawxml struct {
Data string `xml:",innerxml"`
}
type body struct {
Message rawxml `xml:"message"`
}
myXml := body{
Message: rawxml{"This is <myText>"},
}
这将输出(在Go Playground上尝试):
<body>
<message>This is <myText></message>
</body>
Or implementing and using custom xml.Marshaler, but again, this is invalid XML, this is not what you want. What you have right now is exactly what you want.
- 1 回答
- 0 关注
- 73 浏览
添加回答
举报