I have the following code that uses xml.Encode
.
package main
import (
"bytes"
"encoding/xml"
"fmt"
)
type Stuff struct {
Name string `xml:"name"`
}
func main() {
w := &bytes.Buffer{}
enc := xml.NewEncoder(w)
enc.Indent("", " ")
procInst := xml.ProcInst{
Target: "xml",
Inst: []byte("version=\"1.0\" encoding=\"UTF-8\""),
}
if err := enc.EncodeToken(procInst); err != nil {
panic(err)
}
if err := enc.Encode(Stuff{"My stuff"}); err != nil {
panic(err)
}
fmt.Println(w.String())
}
http://play.golang.org/p/ZtZ5FGABmj
It prints:
<?xml version="1.0" encoding="UTF-8"?><Stuff>
<name>My stuff</name>
</Stuff>
How do I make it print with the <Stuff>
start tag on a new line:
<?xml version="1.0" encoding="UTF-8"?>
<Stuff>
<name>My stuff</name>
</Stuff>
Unfortunately I need to write more here so that I can submit the question. Not really sure what to write though because I believe my question is summarized adequately with the above explanation.