Golang encoding/xml.EscapeText() function example

package encoding/xml

EscapeText writes to w(1st parameter) the properly escaped XML equivalent of the plain text data s (2nd parameter).

Golang encoding/xml.EscapeText() function usage example

 package main

 import (
 "encoding/xml"
 "os"
 "fmt"
 )

 func main() {
 str := "\"'&<>"
 err := xml.EscapeText(os.Stdout, []byte(str))

 if err != nil {
 fmt.Println(err)
 }
 }

Output :

&#34;&#39;&amp;&lt;&gt;

Reference :

http://golang.org/pkg/encoding/xml/#EscapeText

Advertisement