Skip to content

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

@jstemmer

Description

@jstemmer
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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions