Standard library / encoding/xml

encoding/xml.NewEncoder()

Creates a streaming encoder writing to the supplied writer. Use Encode or explicitly flush token writes. Expected stdout: '<string>Go</string>\n'.

Formal Syntax & Structure

go syntaxgo
func NewEncoder(w io.Writer) *Encoder

Parameters & Attributes

NameTypeDescription
wio.WriterOutput stream.

Return Value

*Encoder

New XML encoder.

Working Example

Example Snippetgo
package main
import (  "bytes"  "encoding/xml"  "fmt")
func must(e error) {  if e != nil {    panic(e)  }}
func main() {  var out bytes.Buffer  enc := xml.NewEncoder(&out)  must(enc.Encode("Go"))  must(enc.Close())  fmt.Println(out.String())}
Go Reference