Standard library / encoding/xml

encoding/xml.EscapeText()

Writes escaped XML character data, propagating write errors. Expected stdout: 'a&b\n'.

Formal Syntax & Structure

go syntaxgo
func EscapeText(w io.Writer, s []byte) error

Parameters & Attributes

NameTypeDescription
wio.WriterOutput stream.
s[]byteInput text or bytes.

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  must(xml.EscapeText(&out, []byte("a&b")))  fmt.Println(out.String())}
Go Reference