Standard library / encoding/xml

encoding/xml.Encoder.Flush()

Pushes pending encoded bytes to the underlying writer. It does not check for unclosed elements. Expected stdout: 'Go\n'.

Formal Syntax & Structure

go syntaxgo
func (enc *Encoder) Flush() error

Return Value

error

Nil on success; otherwise the operation error.

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.EncodeToken(xml.CharData("Go")))  must(enc.Flush())  fmt.Println(out.String())}
Go Reference