Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

encoding/xml: MarshalIndent output starts with a newline character #3354

Closed
jstemmer opened this Issue Mar 19, 2012 · 6 comments

Comments

Projects
None yet
5 participants
@jstemmer
Copy link
Contributor

jstemmer commented Mar 19, 2012

The output of xml.MarshalIndent always starts with a newline character when the prefix
or indent parameters are non-empty. This results for example in an empty line between
the header and the rest of the xml document when used together with xml.Header.

What steps will reproduce the problem?

package main
import (
    "encoding/xml"
    "fmt"
)
func main() {
    d, _ := xml.MarshalIndent("test", "", "\t")
    fmt.Printf("%#v\n", string(d))
}


What is the expected output?
"<string>test</string>"

What do you see instead?
"\n<string>test</string>"

Which compiler are you using (5g, 6g, 8g, gccgo)?
6g

Which operating system are you using?
linux

Which revision are you using?  (hg identify)
a216dfd16073 tip
@dsymonds

This comment has been minimized.

Copy link
Member

dsymonds commented Mar 19, 2012

Comment 1:

That's still valid XML, right?

Labels changed: added priority-someday, packagechange, removed priority-triage.

@jstemmer

This comment has been minimized.

Copy link
Contributor Author

jstemmer commented Mar 20, 2012

Comment 2:

Yes, it's valid XML afaik. The reason for using MarshalIndent instead of Marshal was to
create a nicely formatted document, so this was a bit unexpected. Just a minor issue.
@rsc

This comment has been minimized.

Copy link
Contributor

rsc commented Sep 12, 2012

Comment 3:

Labels changed: added priority-later, removed priority-someday.

Status changed to Accepted.

@rsc

This comment has been minimized.

Copy link
Contributor

rsc commented Sep 12, 2012

Comment 4:

Labels changed: added go1.1maybe.

@shivakumargn

This comment has been minimized.

Copy link
Contributor

shivakumargn commented Feb 3, 2013

@rsc

This comment has been minimized.

Copy link
Contributor

rsc commented Feb 3, 2013

Comment 6:

This issue was closed by revision 848d10f.

Status changed to Fixed.

@jstemmer jstemmer added fixed labels Feb 3, 2013

@rsc rsc added this to the Go1.1 milestone Apr 14, 2015

@rsc rsc removed the go1.1maybe label Apr 14, 2015

@golang golang locked and limited conversation to collaborators Jun 24, 2016

This issue was closed.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
You can’t perform that action at this time.