Once you write to the ResponseWriter, the bytes start hitting the wire and the headers are sent, if they haven't been sent yet.
If you need to set a Content-Length, you need to write to your own buffer, set the header, and then send everything at once.
var buf bytes.Buffer
err := xml.Marshal(&buf, ...)
...
w.Header().Set("Content-Length", strconv.Itoa(buf.Len()))
io.Copy(w, &buf)