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 關注
- 97 瀏覽
添加回答
舉報