Close the Encoder, indicating that no more data will be written. It flushes any buffered XML to the underlying writer and returns an error if the written XML is invalid (e.g. by containing unclosed elements).
()
| 1015 | // any buffered XML to the underlying writer and returns an error if the |
| 1016 | // written XML is invalid (e.g. by containing unclosed elements). |
| 1017 | func (p *printer) Close() error { |
| 1018 | if p.closed { |
| 1019 | return nil |
| 1020 | } |
| 1021 | p.closed = true |
| 1022 | if err := p.w.Flush(); err != nil { |
| 1023 | return err |
| 1024 | } |
| 1025 | if len(p.tags) > 0 { |
| 1026 | return fmt.Errorf("unclosed tag <%s>", p.tags[len(p.tags)-1].Local) |
| 1027 | } |
| 1028 | return nil |
| 1029 | } |
| 1030 | |
| 1031 | // return the bufio Writer's cached write error |
| 1032 | func (p *printer) cachedWriteError() error { |