Standard library / encoding/xml

encoding/xml.Escape()

Writes XML-escaped text but does not report writer errors. Prefer EscapeText for new code. Expected stdout: 'a<b\n'.

Formal Syntax & Structure

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

Parameters & Attributes

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

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