Skip to content
This repository has been archived by the owner on Feb 24, 2024. It is now read-only.

Add XML header with version and encoding when rendering an XML response #1198

Merged
merged 3 commits into from
Jul 27, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions render/xml.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ func (s xmlRenderer) ContentType() string {
}

func (s xmlRenderer) Render(w io.Writer, data Data) error {
io.WriteString(w, xml.Header)
enc := xml.NewEncoder(w)
enc.Indent("", " ")
return enc.Encode(s.value)
Expand Down
2 changes: 1 addition & 1 deletion render/xml_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@ func Test_XML(t *testing.T) {
bb := &bytes.Buffer{}
err := re.Render(bb, nil)
r.NoError(err)
r.Equal("<user>\n <Name>mark</Name>\n</user>", strings.TrimSpace(bb.String()))
r.Equal("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<user>\n <Name>mark</Name>\n</user>", strings.TrimSpace(bb.String()))
}
}