I am trying to parse a xml file using template.ParseFiles()
.
The xml is :
<?xml version="1.0" encoding="utf-8"?>
<in2>
<unique>{{.}}</unique>
<moe>100%</moe>
</in2>
But after parsing it, the first <
became <
, like this :
&lt;?xml version="1.0" encoding="utf-8"?>
<in2>
<unique>something</unique>
<moe>100%</moe>
</in2>
How can I parse the xml file correctly?
This is my code :
func in2(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "text/xml")
t, err := template.ParseFiles("xml/in2.xml")
if err != nil {
fmt.Println(err)
return
}
unique := "something"
err = t.Execute(w, unique)
if err != nil {
fmt.Println(err)
}
}