Standard library / encoding/xml

encoding/xml.Encoder.Close()

Flushes and checks for unclosed elements. The underlying writer is not closed by this method. Expected stdout: 'true\n'.

Formal Syntax & Structure

go syntaxgo
func (enc *Encoder) Close() 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.StartElement{Name: xml.Name{Local: "a"}}))  fmt.Println(enc.Close() != nil)}
Go Reference