There is the following program:
package main
import (
"encoding/xml"
"fmt"
)
type XMLData struct {
XMLName xml.Name `xml:"tags"`
Tags []Tag `xml:"tag"`
}
type Tag struct {
Text string `xml:"text,attr"`
}
func main() {
var XMLFile XMLDate
XMLFile.Tags = append(XMLFile.Tags, Tag{"Yes, I'm."})
out, err := xml.MarshalIndent(&XMLFile, "", " ")
if err != nil {
panic(err)
}
fmt.Println(string(out))
}
At startup, I expect to get the following output:
<tags>
<tag text="Yes, I'm."></tag>
</tags>
But instead of the expected result, I get the following:
<tags>
<tag text="Yes, I'm."></tag>
</tags>
Instead of the apostrophe symbol, I get its code. How can this be fixed?